#25952
Patrick C
Participant

Welcome to the regex kitchen stew (semi serious; regex seems to drive most people I know either mad or desperate or both)

Anyway one possible RegEx for finding 2 or 4 but not 24 is:
(2(?!4)|(?<!2)4)

Which works on
1
2
3
09
4
5
24
51
1,2,3,09,4,5,24,51,4,2,42,8,4,6,2,8
2
4

To get an idea on what this does
(a|b)
finds either a or b, where
a = 2(?!4) finds 2 without a trailing 4
b = (?<!2)4 finds 4 without a leading 2

Note that I’m not a regex guru.