in reply to Get last 7 characters with regexp (was: PLEASE HELP!!! REGEXP)

You're probably better off using good ole' substr instead. It's built for doing such things.

If you really want to use a regex for some perverse reason -- well, then you're stark raving mad. But in good company. Anyways, think on the following:

EnglishRegex translation
We want to match..$callerid =~ /
..and remember..(
..any character...
..7 times..{7}
..stop remembering..)
..then the end of line..$
..and that's the end of the match./;

Putting that all together, we would get $callerid =~ /(.{7})$/; which would leave the last seven digits in $1. I will reiterate that you don't want to do this, though. It's slow and ugly; use substr. The above was provided as a learning exercise.

Share and enjoy. :)

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Replies are listed 'Best First'.
Re: Re: PLEASE HELP!!! REGEXP
by Sweeper (Pilgrim) on Apr 05, 2002 at 05:50 UTC
    You can code exactly like that in Perl, thanks to the /x modifier. It allows you to insert comments inside the regexp.
    $callerid =~ / # we want to match
                 ( # and remember
                 . # any character
               {7} # 7 times
                 ) # stop remembering
                 $ # then the end of line
                 /x; # and that's the end of the match
    
    In this particular case, this is overkill, but in some cases, it can be very useful in more cmoplicated situations.

    And as all others in this thread have said, I too recommend using substr.