#9743
Stefan
Participant

Conditionals
The character ‘?’ begins a conditional expression, the general form is:
?Ntrue-expression:false-expression
where N is decimal digit.
If sub-expression N was matched, then true-expression is evaluated and sent to output,
otherwise false-expression is evaluated and sent to output.
You will normally need to surround a conditional-expression with parenthesis in order to prevent ambiguities.
For example, the format string “(?1foo:bar)” will replace each match found with “foo” if the sub-expression $1 was matched,
and with “bar” otherwise.
For sub-expressions with an index greater than 9, or for access to named sub-expressions use:
?{INDEX}true-expression:false-expression
or
?{NAME}true-expression:false-expression

conditional expression ?Ntrue-expression:false-expression

In addition, conditional expressions of the following form are recognized:
?Ntrue-expression:false-expression
where N is a decimal digit representing a sub-match.
If the corresponding sub-match participated in the full match, then the substitution is true-expression.
Otherwise, it is false-expression. In this mode, you can use parens () for grouping.
If you want a literal paren, you must escape it as (.

Seams clear, but i have still problems using this.
Some tests:


conditional expression
'?Ntrue-expression:false-expression' test 1

I have:
Test Price 1000
Test Price 100
Test Price 800
---
Find: (.+) (.+) (d{3})(d)
Replace: (?4: too expensive: affordable)
[X] Use RegEx
---
Result:
Test Price 1000 too expensive
Test Price 100
Test Price 800
---
Expected:
Test Price 1000 too expensive
Test Price 100 affordable
Test Price 800 affordable
---
Explanation:
If sub-expression No. 4 match THEN
use 'true-expression'
else 'false-expression'


conditional expression
'?Ntrue-expression:false-expression' test 2

I have:
Color 1 green
Color 2 blue
Color 3 red
The available colors are either green, blue or red.
---
Find: (Color d) (.+)
Replace: (?1:1 2-ich:1 -2-)
[X] Use RegEx
---
Result:
Color 1 green-ich
Color 2 blue-ich
Color 3 red-ich
The available colors are either green, blue or red.
---
Expected:
Color 1 green-ich
Color 2 blue-ich
Color 3 red-ich
The available colors are either -green-, -blue- or -red-.
---
Explanation:
Only if sub-expression No. 1 will match THEN
use 'true-expression'
else 'false-expression'

OK, i will test some more.