Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: minimal match regular expression

by toolic (Bishop)
on Mar 03, 2015 at 16:34 UTC ( [id://1118628]=note: print w/replies, xml ) Need Help??


in reply to minimal match regulara expression

You can use s/// to remove everything after the 1st underscore (inclusive):
use warnings; use strict; my $this_server = 'wppwd01a0099_NET_basp_virtual_adapter'; $this_server =~ s/_.*//; print "$this_server\n"; __END__ wppwd01a0099

Replies are listed 'Best First'.
Re^2: minimal match regular expression
by fionbarr (Friar) on Mar 03, 2015 at 16:37 UTC
    bravo, thanks
      you can also:
      use warnings; use strict; my $match, $pruned = split(/_/, $_); print $match
      at work so cant* test it haha

        ... and it doesn't work haha.

        Tested, works:

        c:\@Work\Perl>perl -wMstrict -le "$_ = 'wppwd01a0099_NET_basp_virtual_adapter'; my ($match) = split(/_/, $_); print qq{'$match'}; " 'wppwd01a0099'


        Give a man a fish:  <%-(-(-(-<

Re^2: minimal match regular expression
by fionbarr (Friar) on Mar 03, 2015 at 19:40 UTC
    thanks...this is the one I ended up with after finding out I had some occurances of an internal '-' which choked on (\w+?)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found