s_gaurav1091 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: regular expression
by jbrugger (Parson) on Jul 27, 2005 at 04:58 UTC
    What exactly do you want to match?
    This line in a big file? some words out of it?
    please read how (not) to ask a question if you want help.

    #!/usr/bin/perl use Data::Dumper; use strict; my $ln = "HOST_RESOURCE_MONITOR rtbd:service=ResourceMonitorService,na +me=ResourceMonitor,type=HOST true Started 1 day, 12 hours, 2 minutes, + 30 seconds and 476 milliseconds"; if ($ln =~ m/^HOST.*?seconds$/ ) { print "ok"; }


    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
Re: regular expression
by ZlR (Chaplain) on Jul 27, 2005 at 08:06 UTC
    maybe /\w+/ ?
    That's "a very general RE"     ;)-
    i.e if you don't tell us what you want to match, it's not gonna be easy to help you

Re: regular expression
by brian_d_foy (Abbot) on Jul 27, 2005 at 11:57 UTC

    The regex you need depends on what you want to match or extract. By guessing what you want be interested in, I came up with this regex:

    $string = "HOST_RESOURCE_MONITOR rtbd:service=ResourceMonitorService +,name=ResourceMonitor,type=HOST true Started 1 day, 12 hours, + 2 minutes, 30 seconds and 476 milliseconds"; if( $string =~ m/ ^HOST_RESOURCE_MONITOR \s+ rtbd: service=(\S+), name=(\S+), type=(\S+) \s+ (\S+) \s+ Started \s+ (\d+) \s+ days? , \s+ (\d+) \s+ hours? , \s+ (\d+) \s+ minutes? , \s+ (\d+) \s+ seconds? \s+ and \s+ (\d+) \s+ milliseconds? /x ) { print <<"HERE"; Service: $1 Name: $2 Type: $3 Boolean: $4 Days: $5 Hours: $6 Minutes: $7 Seconds: $8 Milli: $9 HERE } else { print "No match!\n"; }
    --
    brian d foy <brian@stonehenge.com>