Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: regex trouble

by blackgoat (Acolyte)
on Mar 05, 2010 at 10:32 UTC ( #826937=note: print w/replies, xml ) Need Help??


in reply to Re^3: regex trouble
in thread regex trouble

I have to run a command in unix. And I have to match this expression from whatever output I get. I tried doing the following:

my $var = 'command'; my ($exp) = $var =~ m/(v\d{2}\.\d{2})-([a-z]\d{3})/;

The same is followed by a html script in which the value of $exp must appear. But I am unable to do so...

Can u pls help!

Thanks

BG

Replies are listed 'Best First'.
Re^5: regex trouble
by amir_e_a (Hermit) on Mar 05, 2010 at 11:03 UTC

    You probably want to do something like

    my $var = `command`;

    Notice that the single quotes were replaces by backticks. There are certain problems with using backticks, but it's usually OK to use them to run a simple and safe command.

    Also, your current code will only capture v09.11. If you want to capture v09.11-e020, use this:

    my ($exp) = $var =~ m/(v\d{2}\.\d{2}-[a-z]\d{3})/;

      I'm getting the following error:

      Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE v\d{2}\.\d{2}(a-z\d{3})/

        You probably only need one opening bracket in the beginning and one closing in the end:

        m/(v\d{2}\.\d{2}-[a-z]\d{3})/

        Brackets should usually match - for every opening bracket there must be one closing bracket.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2020-01-18 14:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?