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

Re: regular expressions with commas?

by osunderdog (Deacon)
on Dec 10, 2005 at 11:02 UTC ( [id://515707]=note: print w/replies, xml ) Need Help??


in reply to regular expressions with commas?

Well, here is what I would start with:

use strict; while(<DATA>) { #using re match. # match beginning, anything except comma, # followed by a comma and 'Y' if(m/^([^,]+),Y/) { print "RE Name:" . $1 . "\n"; } } __DATA__ davis,N brown,Y smith,Y,N,B jones,N,Y,B,A clarke,Y,N,Y

Or Perhaps:

use strict; while(<DATA>) { my @data = split(','); if($data[1] eq 'Y') { print "RE Name:" . $data[0] . "\n"; } } __DATA__ davis,N brown,Y smith,Y,N,B jones,N,Y,B,A clarke,Y,N,Y

Hazah! I'm Employed!

Replies are listed 'Best First'.
Re^2: regular expressions with commas?
by chas (Priest) on Dec 10, 2005 at 14:49 UTC
    Those both match given the string "Blah,Y,X", which has a substring ending with ",Y", but doesn't itself end with that sequence. (It isn't completely clear to me what the OP wanted, though...)

      I interpreted it as meaning a ",Y" after the name string. Many others interpreted it as meaning a ",Y" at the end of the line. The OP wasn't clear so I figure I would share my interpretation.

      Hazah! I'm Employed!

Re^2: regular expressions with commas?
by webshark (Acolyte) on Dec 10, 2005 at 11:33 UTC
    cheers guys... works a treat..

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-18 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found