I've been trying to match a single IPv4 address out of an xml string and bind it to a variable for later use. I've tested the regex itself in some online testers and it appears to function with some sample outputs. I've also tested the BASH_REMATCH similar to the one below with a much simpler regex and pattern and it works. So is there a problem with my regex itself not compatible with bash?
Sample Script...
#!/bin/bash
rawxml="<ip-netmask>1.2.3.4/32</ip-netmask>"
ipv4regex="(((?:|\.)(2(?:5[0-5]|[0-4]\d)|1?\d?\d)){4})"
# Finding IP from $rawxml and binding it to its own variable
if [[ $rawxml =~ $ipv4regex ]]; then
ipfound=${BASH_REMATCH[1]}
fi
echo "IP found is "$ipfound""
Expected output here would be....
"IP Found is 1.2.3.4"