• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Regex for *either or both* of last two characters are not digits?

Resolved: Regex for *either or both* of last two characters are not digits?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

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!

regex
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: I am facing ERR_HTTP2_PROTOCOL_ERROR on my website

27/03/2023

Resolved: TypeScript does not recognize properties when instantiating interface array

27/03/2023

Resolved: How to make statement case insensitive when uploading a dta file with specified columns?

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.