Link to home
Start Free TrialLog in
Avatar of ambuli
ambuliFlag for United States of America

asked on

Perl: How to find a numric value preceding a string

Hi Experts,

I need to find the number in the following string.

THREAD_NAME: spent time 34.4 (units %)
I want to get the 34.4 from this line.  The numeric value will always precede the (units %) string.  But the other words in the string will vary.

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can also try this one:

my ($number) = $string =~ m/([0-9.]+)\s*\(units/;

Open in new window