Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: regex needed with match operator

by broquaint (Abbot)
on Apr 28, 2003 at 13:37 UTC ( [id://253683]=note: print w/replies, xml ) Need Help??


in reply to regex needed with match operator

Here's a fix for your regex
if(m[/\w+/foo]) { s[.* /(\w+) /foo \z]($1)x; ... }
Here's a simpler solution which grabs what is matched (as opposed to modifying the contents @FILES as your code does)
print m{ /(\w+) /foo\z }x, "\n" for @FILES;
See. perlre for more info on the regex used.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re^2: regex needed with match operator (push for == map)
by Aristotle (Chancellor) on Apr 28, 2003 at 13:56 UTC
    And once you try to store the retrieved bits, you arrive at something like
    my @name; push @name, m{ /(\w+) /foo\z }x for @FILES;
    which, of course, is a map in disguise:
    my @name = map m{ /(\w+) /foo\z }x, @FILES;

    Makeshifts last the longest.

Re: Re: regex needed with match operator
by Anonymous Monk on Apr 28, 2003 at 13:43 UTC
    Thanks broquaint,
    Would you mind explaining exactly what the \z and x are doing in the regex?

    Thanks again

      Would you mind explaining exactly what the \z and x are doing in the regex?
      Sure, to quote the docs
      \z Match only at end of string
      This is very similar to $ except $ matches the end of a line or before a newline.
      x Extend your pattern's legibility by permitting whitespace and comments.
      As it says, it allows for more readable regex, which is generally desirable considering the acute succinctness of regular expressions.
      HTH

      _________
      broquaint

        Thank you,
        It makes a lot more sense now, and I didn't realize the differnece between $, and \z, but now I do.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-26 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found