Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: About regular expression

by Trimbach (Curate)
on Mar 15, 2002 at 02:49 UTC ( #151892=note: print w/replies, xml ) Need Help??

in reply to About regular expression

First, you're missing a ~ character. It should be: -- Not necessary. There's an implicit match against $_.--geb

(code deleted)

Second, let's break it down:

my ($label) =~ / # begin \. # find a literal . ( # start capturing [^\.] # Any character that isn't a \ or . * # zero or more ) # stop capturing $ # only match from the end of the string / # end;
In a nutshell this will match the "extension" of the data you provided, i.e. the "five" in "one.five" or the "12" in "two.ten.12". What's matched is captured into $label.

There's lots of info on regexes both here and in the regular Perl documentation. They can be challenging at first, but are well worth the effort to figure out. :-D

Gary Blackburn
Trained Killer


Replies are listed 'Best First'.
Re: Re: About regular expression
by abstracts (Hermit) on Mar 15, 2002 at 03:08 UTC
    Sorry, but I don't think there is a missing '~'. $label is assigned the matched between the parens (everything after the dot). It's not being matched by the re.


      Yeah, you're right. There's an implicit match against $_ there that I didn't see. I guess it just wasn't implied enough. :-D

      Gary Blackburn
      Trained Killer

Re: Re: About regular expression
by Juerd (Abbot) on Mar 15, 2002 at 21:13 UTC

    [^\.] # Any character that isn't a \ or .

    Not exactly. The backslash is used as an escape character, not only in the regex itself, but in character classes too. Even though it's not necessary at all to escape a dot in a character class, Perl removes the backslash itself (Perl always does something when you use a backspace in an interpolated string, unlike some languages where "\q\n" is backslash, q, newline. In Perl, "\q\n" is q, newline.).

    [^\.] # Any character that is not . [^.] # Any character that is not .


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://151892]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2021-10-24 18:26 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (89 votes). Check out past polls.