Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: regex needed

by Crian (Chaplain)
on Nov 18, 2008 at 13:58 UTC ( #724270=note: print w/ replies, xml ) Need Help??


in reply to Re: regex needed
in thread regex needed

Perhaps this one is, what you are looking for?

C:\Daten\perl>cat match.pl #!/usr/bin/perl use strict; use warnings; my $var = 'Sensor30'; while (<DATA>) { print if /^>?\Q$var\E$/; } __DATA__ >Sensor30 >FooSensor30 > Sensor30 Sensor300 Sensor30 >Sensor3 C:\Daten\perl>perl match.pl >Sensor30 Sensor30

Without a regular expression:

C:\Daten\perl>cat match.pl #!/usr/bin/perl use strict; use warnings; my $var = 'Sensor30'; while (<DATA>) { chomp; print "$_\n" if $_ eq $var or $_ eq '>' . $var; } __DATA__ >Sensor30 >FooSensor30 > Sensor30 Sensor300 Sensor30 >Sensor3 C:\Daten\perl>perl match.pl >Sensor30 Sensor30


Comment on Re^2: regex needed
Select or Download Code
Replies are listed 'Best First'.
Re^3: regex needed
by Anonymous Monk on Nov 18, 2008 at 14:11 UTC
    Thats what I was missing...Thank you!

    I modified it a bit to include the space if it exists:

    my $var = 'Sensor30'; while (<DATA>) { chomp; if (/^(>\s*)?\Q$var\E$/) { print "MATCH => $_\n"; } } __DATA__ >Sensor30 >FooSensor30 > Sensor30 Sensor300 Sensor30 >Sensor3

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (16)
As of 2015-07-30 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls