I have Bash script below, trying to capture last digits of 'pingnet' but can not get a match. I verified in regex101 and my regex is correct:
pingnet="pingcount,site=DC,cur=200 total-up=988"
regex='(\d+)$'
if [[ $pingnet =~ $regex ]]
then
echo "YES"
echo "${BASH_REMATCH[1]}"
else
echo "NOT"
echo "${BASH_REMATCH[1]}"
fi
The result of running script is NOT.
\d
doesn't work with bash's ERE, you need to use[0-9]
– jesse_b Jul 19 '18 at 20:27\d
as explained in Bash =~ regex and https://regex101.com/ – Jul 19 '18 at 20:32