Click here to get back home

Simple Regular Expression Help

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Simple Regular Expression Help vunet.us 05-16-2007
Posted by vunet.us on May 16, 2007, 1:59 pm
Please log in for more thread options


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+)\)/;


Posted by Greg Bacon on May 16, 2007, 3:07 pm
Please log in for more thread options


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

Posted by Tim S on May 16, 2007, 4:24 pm
Please log in for more thread options


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

Posted by vunet.us on May 17, 2007, 9:11 am
Please log in for more thread options


> 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.


Posted by Keith on May 18, 2007, 1:09 pm
Please log in for more thread options


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


Similar ThreadsPosted
How to parse with regular expression... May 5, 2005, 6:33 am
Regular Expression Generator June 26, 2006, 1:42 am
regular expression problem ? and * characters May 28, 2006, 7:02 am
trickiness (?) calling regular subroutines from OO methods August 23, 2004, 11:16 am
XML::Simple Help? April 23, 2005, 5:09 pm
Help in XML::Simple July 1, 2005, 9:12 pm
Getopt::Simple V 1.47 July 29, 2004, 7:18 am
Simple question September 15, 2005, 4:17 am
Filter::Simple bug? December 21, 2004, 9:54 pm
LWP::Simple getstore January 6, 2005, 7:52 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap