Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Pattern matching

by mdillon (Priest)
on Mar 26, 2002 at 00:28 UTC ( [id://154283]=note: print w/replies, xml ) Need Help??


in reply to Pattern matching

Try this:
$single = "12"; @allbonds = qw(12 13 123 12,45 123,45 12,345 1234 12345); @somebonds = grep /^$single(?:\d|,\d{2})$/o, @allbonds;

Replies are listed 'Best First'.
Re: Re: Pattern matching
by Dogg (Scribe) on Mar 26, 2002 at 00:44 UTC
    Thanks. That works perfectly.
    I've never used grep (I've always made do with simpe matching).
    This will make me learn it.

    Thanks again.

      You're missing the point. It's not that he's using grep, but that he's anchored the match with a $ at the end of the regexp that's important. You were matching more than you thought you should be because you hadn't specified that the regexp had to match the entire string.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found