0
votes

i need a regex to find all string that is surrounded by %

example:

A=%Test1% OR B = %Test2% AND (C=%Test3 OR C = %Test4)

what i need are the strings:

%Test1%, %Test2%, %Test3% and %Test4%

thanks.

2
Shouldn't that be %Test3 OR C = %? %Test4 is not surrounded by %, so either your specification is lacking or your input is. - deceze
What have you tried so far? You can easily test regexes online using sites like gskinner.com/RegExr - row1

2 Answers

4
votes

Just use

%[^%]+%

Which matches a percent sign, followed by a non-zero number of non-percent characters and another percent.

0
votes

Maybe %[[:alnum::]+% would do the job?