0

This question already has an answer here:

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.

marked as duplicate by Jesse_b, slm bash Jul 19 '18 at 20:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Bash's regex syntax does not recognize \d; use [[:digit:]] instead:

pingnet="pingcount,site=DC,cur=200 total-up=988"
regex='([[:digit:]]+)$'

Not the answer you're looking for? Browse other questions tagged or ask your own question.