Regex \d match in RH

Guys - any advice on why the following \d match doesn’t work on most flavors of RH. On windows it’s fine.

if exists (addresses whose (it as string != “0.0.0.0”) of ip interfaces whose (not loopback of it) of network as string) whose (exists match (regex “^\d{1,3}.\d{1,3}.(19\d).\d{1,3}”) of it) then “my network” else “N/A”

Thanks.

It’s down to the regex libraries used on the various OSs.

Use the posix bracket expressions

(regex “^[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.(19[[:digit:]])\.[[:digit:]]{1,3}”)

should work on any OS

2 Likes

thanks for the reply - any advantage using regex over native substrings relevance ?

if exists (addresses whose (it as string != “0.0.0.0”) of ip interfaces whose (not loopback of it) of network as string) whose (tuple string item 2 of concatenation ", " of substrings separated by “.” of it >= “190” AND tuple string item 2 of concatenation ", " of substrings separated by “.” of it <= “199” of it) then “my network” else “N/A”

Jason gave me some of these query to pull the string which has dot… see if any way you can manipulate it.

(substrings separated by " " of substrings separated by “%09” of it ) whose (it contains “.”) of lines starting with “server” of file “/etc/ntp.conf”
(parenthesized parts 1 of matches(regex("^server[[:space:]]+([^[:space:]]+)")) of it) of lines starting with “server” of file “/etc/ntp.conf”
(parenthesized parts 1 of matches(regex("^server[[:space:]]+(([[:alnum:]]|.|-|_)+)")) of it) of lines starting with “server” of file “/etc/ntp.conf”

I don’t know whether regex gives any advantage for this over native relevance, but your question seemed to be about regex not working reliably on all flavours of RH.

I will quite often write a variant of my relevance using regex to practice. Quite often the regex is slower but sometimes it will be easier to understand (and therefore more maintainable).