Regex relevance on linux vs windows

I’m working on some content that looks at a computer name to see if it’s relevant or not. Problem is, on the actual linux box I’m planning on running this, the regex always comes back false.

Windows QnA:

Q: exists matches (regex "^\w\w\d\d\d\w*\.") of "bb123bla.bl123.domain.com"
A: True
T: 0.103 ms
I: singular boolean

Linux QnA:

Q: exists matches (regex "^\w\w\d\d\d\w*\.") of "bb123bla.bl123.domain.com"
A: False
T: 115

Did I find a bug or is there a difference where I can’t use this in LInux for some reason?

And yes I know there are simpler relevance ways of doing this, but this is a broken down simpler version of a much larger regex I’m working on… and this should just work anyway and its :face_with_symbols_over_mouth: me off

I ran into this a while back and have a long thread on it here that I can try to find later. Basically it’s due to differences in the underlying regex libraries provides by the OS. The safest methods are to use only POSIX-compliant regular expressions rather than something like Perl-compatible regex. This gets ugly, but is doable.

Rather than expressions like “\w” for word and “\s” for whitespace, you have to use “[[:word:]]” and “[[:space:]]” if I recall correctly.

Edit: fixed expression and here’s the discussion Digit \d matching in regex

3 Likes

Interesting. Looks like you can also use [0-9] and/or [a-zA-Z] on Linux successfully

Q: exists matches (regex "^[a-zA-Z][a-zA-Z][0-9][0-9][0-9][a-zA-Z]*.") of "bb123bla.bl123.domain.com"
A: True

Yeah I’d expect that to work too. The main differences I saw were in shortcuts like \d and \w and \s. The AIX parser was even more strict than Linux (but I also had an older client version on AIX).