Simple Regular Expression Help

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+)\)/;
vunet.us [ Mi, 16 Mai 2007 19:59 ] [ ID #1713722 ]

Re: Simple Regular Expression Help

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
gbacon [ Mi, 16 Mai 2007 21:07 ] [ ID #1713723 ]

Re: Simple Regular Expression Help

vunet.us [at] 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
Tim S [ Mi, 16 Mai 2007 22:24 ] [ ID #1713725 ]

Re: Simple Regular Expression Help

On May 16, 4:24 pm, Tim S <t... [at] dionic.net> wrote:
> vunet... [at] 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.
vunet.us [ Do, 17 Mai 2007 15:11 ] [ ID #1714465 ]

Re: Simple Regular Expression Help

On May 16, 12:59 pm, vunet... [at] 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
keith [ Fr, 18 Mai 2007 19:09 ] [ ID #1715354 ]
Perl » comp.lang.perl.modules » Simple Regular Expression Help

Vorheriges Thema: Accessing listbox using perl?
Nächstes Thema: Problems while installing win32::api