Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Regex help!

by shmem (Chancellor)
on Jun 09, 2013 at 08:33 UTC ( #1037917=note: print w/replies, xml ) Need Help??


in reply to Regex help!

Basically, I need to extract disk capacity from the data center description which basically has a numeric value preceding the unit of measure like GB
...
echo $x | sed "s/^[^0-9]*\([0-9]*[.]*[0-9]*\)[^0-9A-Z]*GB.*/\1/g"

Why so complicated? This should do:

echo $x | sed "s/.\+ \([0-9]\+\)GB.*/\1/g"

But as LanX says, sed(1) doesn't use PCRE. Read perlrun and perlre to understand the following:

echo $x | perl -ple 's/.+?(\d+)\s?GB.*/$1/'
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1037917]
help
Chatterbox?
[Corion]: Discipulus: Nah, I'm thinking of posting more short stuff, but not all of it is fit for blogs.perl.org, more something a bit longer than Twitter but shorter than my usual b.p.o module posts
[Corion]: But Google+ is tedious and I'd like to keep my posts on an open platform instead, which can be followed via RSS

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2017-05-26 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?