I use regex on and off. A situation arose where I needed to use repetition matching, something I knew existed but had never used before.
I needed to match a string with at most 36 characters. Using the regex below worked but it also matched strings with commas inside them
.{,36}
I specified that I did not wish to have commas in the string, resulting in this next expression.
[^,].{,36}
After this change, the expression stopped matching the target strings e.g. 9F7096D0D20949ACB2DA1EE57488F015
or
99AD7ECC-222A-AC8A-4BF8-F04B159DDBFB
It instead matched a string like
9200','LI','NA',null,'Y','L','N','N',
Realizing that the attempt to leave out the commas had caused the trouble, I adjusted the expression, which matched the desired strings.
[^,]{,36}
No comments:
Post a Comment