in reply to regex matching number

Come to think of it it would have been good it I were able to debug a regex:
perl -de "$s=qq(1a2a3a4a5a); if ($s=~/(\d+)/){print $1};" Default die handler restored. Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(-e:1): $s=qq(1a2a3a4a5a); if ($s=~/(\d+)/){print $1}; DB<1> n main::(-e:1): $s=qq(1a2a3a4a5a); if ($s=~/(\d+)/){print $1}; DB<1> p $_ DB<2>
Is there any way to do this?

Celebrate Intellectual Diversity

Replies are listed 'Best First'.
Re: Re: regex matching number
by shenme (Priest) on Sep 10, 2003 at 21:36 UTC
    Works for me, that is, I am able to play with conditions and see what happens as I experiment.
      DB<1> $s=qq(1a2a3a4a5a); if ($s=~/(\d+)/){print $1};
    1
      DB<2> $s=qq(1a2a3a4a5a); while ($s=~/(\d+)/g){print $1};
    12345
      DB<3> $s=q(1a22b333c4567d89);
    
      DB<4> $re=qr~(\d+)~;
    
      DB<5> print $1 while $s =~ /$re/g;
    122333456789
      DB<6> $re=qr~(\d{3,})~;
    
      DB<7> print $1 while $s =~ /$re/g;
    3334567
    
    Just keep playing with inputs and patterns until you understand what is going on   (or until you get something that works and then put 'study' on your to-do list ;-)

    And strangely enough, shortly before/after your question, in another thread antirice offered a suggestion to use a tool to try explaining what a RE means - see Re: Pattern Matching Question.   Hey, that became next on my todo list!