Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: regular expressions with commas?

by osunderdog (Deacon)
on Dec 10, 2005 at 11:02 UTC ( #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
Node Status?
node history
Node Type: note [id://515707]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2020-12-05 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (63 votes). Check out past polls.

    Notices?