vendredi 19 avril 2019

If-Then-Else regex statement

I am trying to form a RegEx expression that would capture if it is in the string otherwise capture

I tried something along the lines of: (IF)(?(1)THEN|ELSE)

meaning the capture would be IFTHEN (in case IF is found) or ELSE (in case IF is not found)

For example:

(apple1\d)(?(1)|apple2\d)

case1: for the string: pear33 apple14 apple24 orange22 orange44

Result would be: apple14

case2: In contrast for the string: pear33 apple24 orange22 orange44

The result would be: apple24 (since there is no apple1 it would capture apple2\d)

My regex expression works well for case1 it returns apple14 however the ELSE doesn't work. I expect it to return apple24 for case2

Aucun commentaire:

Enregistrer un commentaire