in reply to Pattern matching

first you go throuh the perldoc for regular expressions.

$a=~ /(tom)(dick|harry|john)/;

Prasad

Replies are listed 'Best First'.
Re^2: Pattern matching
by davido (Cardinal) on Jan 05, 2005 at 17:35 UTC
    $a=~ /(tom)(dick|harry|john)/;

    I really doubt that the OP wanted to match "tomdick", "tomharry" and "tomjohn". Shouldn't there be some provision for whitespace in the string too? ;) The other problem with that solution is, what if the string contains "john tom". I think the OP wants to match even if the two names are in different order. ...as long as tom and any of the other three names exist. That's why the two regexp approach works so elegantly.


    Dave

Re^2: Pattern matching
by rupesh (Hermit) on Jan 05, 2005 at 12:48 UTC
Re^2: Pattern matching
by prasadbabu (Prior) on Jan 05, 2005 at 12:47 UTC
    I assumed the string as tom and any one of the other (dick,harry,john).

    Prasad