Simple Regular Expression Help

Simple Regular Expression Help

am 16.05.2007 19:59:02 von vunet.us

How can I strip this line with regular expession to get 12345 number
within brackets:

$line = "some text is here (12345 ms)";

This did not work:

$text = $line;
$text =~ m/\((\d+)\)/;

Re: Simple Regular Expression Help

am 16.05.2007 21:07:34 von gbacon

You also posted this question to comp.lang.perl.misc. Please
don't multi-post.

Greg
--
Pulling together is the aim of despotism and tyranny. Free men pull in
all kinds of directions.
-- Terry Pratchett

Re: Simple Regular Expression Help

am 16.05.2007 22:24:36 von Tim S

vunet.us@gmail.com wrote:

> How can I strip this line with regular expession to get 12345 number
> within brackets:
>
> $line = "some text is here (12345 ms)";
>
> This did not work:
>
> $text = $line;
> $text =~ m/\((\d+)\)/;

$text =~ m/\((\d+)[^\)]*\)/;
or
$text =~ m/\((\d+).*?\)/;

HTH

Tim

Re: Simple Regular Expression Help

am 17.05.2007 15:11:30 von vunet.us

On May 16, 4:24 pm, Tim S wrote:
> vunet...@gmail.com wrote:
> > How can I strip this line with regular expession to get 12345 number
> > within brackets:
>
> > $line = "some text is here (12345 ms)";
>
> > This did not work:
>
> > $text = $line;
> > $text =~ m/\((\d+)\)/;
>
> $text =~ m/\((\d+)[^\)]*\)/;
> or
> $text =~ m/\((\d+).*?\)/;
>
> HTH
>
> Tim

Thanks Tim.

I posted the question again because there were a few hours of delay
for my post to show up.

Re: Simple Regular Expression Help

am 18.05.2007 19:09:54 von keith

On May 16, 12:59 pm, vunet...@gmail.com wrote:
> How can I strip this line with regular expession to get 12345 number
> within brackets:
>
> $line = "some text is here (12345 ms)";
>
> This did not work:
>
> $text = $line;
> $text =~ m/\((\d+)\)/;

Why not:

$number = $1 if ($line =~ /\((\d+)\D*\)/);

# ??? -- Keith