Question:
I can’t figure out the proper regular expression for this… Most of my data ends with digits as the last two characters. A subset ends with where either one or both of the last two are non-digits. So xyz99 is normal and I’m able to find those records with"*[0-9][0-9]$"
. If I change that to "*[^0-9][^0-9]$"
then I get records where both are non-digits.I don’t know regex well enough to match all of the following with a single regex: xy9z, xyz9, xyzw, but not matching xyz99.
I prefer a single regex, but (already know how to and) can work-around with multiple.
Thanks for any help.
Answer:
[^\d]$|[^\d].$
should do the trick
https://regex101.com/r/PsZxLj/2
It matches anything that doesn’t end in a digit OR anything where the 2nd to last character isn’t a digit. Lots of ways to do this, but pick one that is easy for you to read and maintain. ๐ Good luck!
If you have better answer, please add a comment about this, thank you!