Use this regular expression to find the invalid pattern. It's flexible enough to match any expressions for a
, b
, c
, and d
, not just simple variables.
(.*\s*\?)(.*):\s*(.*)\?\s*:\s*(.*)
Option 1: Fix to (a ? b : c) ?: d
Use this replacement pattern if you want to group the entire first ternary as the condition for the second.
Code snippet
($1 $2 : $3) ?: $4
This pattern wraps the first three capture groups in parentheses, creating a single, valid expression.
Option 2: Fix to a ? b : (c ?: d)
Use this replacement pattern if you want to nest the second ternary inside the first. This is a common and often more readable approach.
Code snippet
$1 $2 : ($3 ?: $4)