Can't capture regex group? [duplicate]

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite













This question already has an answer here:



  • Why does my regular expression work in X but not in Y?

    1 answer



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.







share|improve this question













marked as duplicate by Jesse_b, slm♦ bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 19 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.










  • 2




    d doesn't work with bash's ERE, you need to use [0-9]
    – Jesse_b
    Jul 19 at 20:27






  • 2




    Maybe this will help: bash ERE regular expressions do not have the d as explained in Bash =~ regex and https://regex101.com/
    – Isaac
    Jul 19 at 20:32

















up vote
0
down vote

favorite













This question already has an answer here:



  • Why does my regular expression work in X but not in Y?

    1 answer



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.







share|improve this question













marked as duplicate by Jesse_b, slm♦ bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 19 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.










  • 2




    d doesn't work with bash's ERE, you need to use [0-9]
    – Jesse_b
    Jul 19 at 20:27






  • 2




    Maybe this will help: bash ERE regular expressions do not have the d as explained in Bash =~ regex and https://regex101.com/
    – Isaac
    Jul 19 at 20:32













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • Why does my regular expression work in X but not in Y?

    1 answer



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.







share|improve this question














This question already has an answer here:



  • Why does my regular expression work in X but not in Y?

    1 answer



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.





This question already has an answer here:



  • Why does my regular expression work in X but not in Y?

    1 answer









share|improve this question












share|improve this question




share|improve this question








edited Jul 19 at 20:26









slm♦

232k65479649




232k65479649









asked Jul 19 at 20:23









irom

184110




184110




marked as duplicate by Jesse_b, slm♦ bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 19 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.






marked as duplicate by Jesse_b, slm♦ bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jul 19 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.









  • 2




    d doesn't work with bash's ERE, you need to use [0-9]
    – Jesse_b
    Jul 19 at 20:27






  • 2




    Maybe this will help: bash ERE regular expressions do not have the d as explained in Bash =~ regex and https://regex101.com/
    – Isaac
    Jul 19 at 20:32













  • 2




    d doesn't work with bash's ERE, you need to use [0-9]
    – Jesse_b
    Jul 19 at 20:27






  • 2




    Maybe this will help: bash ERE regular expressions do not have the d as explained in Bash =~ regex and https://regex101.com/
    – Isaac
    Jul 19 at 20:32








2




2




d doesn't work with bash's ERE, you need to use [0-9]
– Jesse_b
Jul 19 at 20:27




d doesn't work with bash's ERE, you need to use [0-9]
– Jesse_b
Jul 19 at 20:27




2




2




Maybe this will help: bash ERE regular expressions do not have the d as explained in Bash =~ regex and https://regex101.com/
– Isaac
Jul 19 at 20:32





Maybe this will help: bash ERE regular expressions do not have the d as explained in Bash =~ regex and https://regex101.com/
– Isaac
Jul 19 at 20:32











1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










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



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





share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote



    accepted










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



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





    share|improve this answer

























      up vote
      3
      down vote



      accepted










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



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





      share|improve this answer























        up vote
        3
        down vote



        accepted







        up vote
        3
        down vote



        accepted






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



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





        share|improve this answer













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



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






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Jul 19 at 20:27









        Jeff Schaller

        30.8k846104




        30.8k846104












            Th1EgLlh,9PModTuGTqHga Wx16Ybo9x4
            FdQkyJ7efOoI9dsRfS,RpNP,72Gc

            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            How many registers does an x86_64 CPU actually have?

            Displaying single band from multi-band raster using QGIS