I have the following pattern that matches placeholders such as (%s
, %16.6fAl
, %d
, etc.):
%([a-z]+)\b|%([a-z0-9\.]{2,20})\b
I do, however, need to ignore the following placeholders:
%w
%1w
%2w
%3w
%O
%M
I've tried to look up and check the forum, but I'm afraid my regex knowledge is limited. Is there anyone out there that may have a solution?
If you want to match all placeholders except five very specific ones, and your code allows it, the easiest way is probably to first match all the placeholders, then (if matched) use another regexp to check for the five "prohibited" ones and ignore them. Writing a RegExp that will match %d
, %1d
, %4d
, %4w
but will not match %1w
will be... interesting. Certainly possible, just not fun.
Your might try this one. It fulfills your given examples.
%([a-lnp-vx-z]+)\b|%((?:[0-9][^w]{1,19})|(([a-z.]{2,20})))\b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With