Newbie: Parsing help

L

lepi

Hi,

I know very little about regex, but I think it can help me now.

If I have string like this:

$some="I have something here. Speed: 200 km/h. Color is white. OK!!";

I want to parse this string and get two new strings

$speed="200";
$color="white";

How can I do this???

Please explain given regex...

Thanks
 
M

Michael Slass

lepi said:
Hi,

I know very little about regex, but I think it can help me now.

If I have string like this:

$some="I have something here. Speed: 200 km/h. Color is white. OK!!";

I want to parse this string and get two new strings

$speed="200";
$color="white";

How can I do this???

try this:

my ($speed, $color) = ($some =~ m/Speed:\D*(\d+).*?Color is\W+(\w+)/g);
Please explain given regex...

To understand why this works (or doesn't for you), you can read all
about perl regular expressions with:

perldoc perlre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top