Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

help in matching

by uva (Sexton)
on Feb 08, 2006 at 14:51 UTC ( [id://528810]=perlquestion: print w/replies, xml ) Need Help??

uva 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: help in matching
by Fletch (Bishop) on Feb 08, 2006 at 15:07 UTC

    The '-' character is for ranges, but only inside a character class. /[a-d]/ would match one single character 'a', 'b', 'c', or 'd'. /a-d/ matches an 'a' followed by a '-' followed by a 'd'. Your regex would match a dash followed by 'process' (i.e. '-process'); since your sample data does not contain a dash followed by 'process' the match fails.

Re: help in matching
by mickeyn (Priest) on Feb 08, 2006 at 15:13 UTC
    in this case the RE just looks for the character '-' which does not precede 'process'.
    to be used as range operator it should be placed within a character class.

    Enjoy, Mickey

Re: help in matching
by MCS (Monk) on Feb 08, 2006 at 17:01 UTC

    What you are currently doing is searching for "-process" in this $_ (magic operator) which you have assigned the value 'process1.' Running this yields nothing because '-process' is not in 'process1.' A better approach would be:

    my $string = 'process1'; if ($string =~ /process/) { print "success"; }

    This searches $string for the text "process." (for more information on these matches read up on regular expressions)

      thanks for your replies friends..... i understood..
Re: help in matching
by svenXY (Deacon) on Feb 08, 2006 at 15:15 UTC
    Hi,
    range operator here means that e.g. [a-z] means one character in the range of a-z.
    If you want your example to match, just omit the hyphen and it will match.

    It is however not a good idea to set $_ as it is a magic variable ( see perlvar).
    Regards,
    svenXY

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://528810]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2025-01-14 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (38 votes). Check out past polls.