cajun has asked for the wisdom of the Perl Monks concerning the following question:
What I'm not clear on is the difference between the actions of the [ ] and ( ). From the actions of my test script, I believe the (htm|asp) is an 'or' condition (htm or asp). I'm not clear on why the [htm|asp] is matching on the third line of data.#!/usr/bin/perl use warnings; use strict; while (<DATA>){ print "Match on line $. with []\n" if (/[htm|asp]/); print "Match on line $. with ()\n" if (/(htm|asp)/); } __DATA__ optout.htm optout.asp optout.php OUTPUT: Match on line 1 with [] Match on line 1 with () Match on line 2 with [] Match on line 2 with () Match on line 3 with []
Links to more info appreciated.
Thanks,
Mike
Update: Thanks davido and Enlil. Perfect explanations. Thanks for the links for more info too.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex question
by davido (Cardinal) on Aug 08, 2005 at 06:40 UTC | |
Re: Regex question
by Enlil (Parson) on Aug 08, 2005 at 06:44 UTC | |
Re: Regex question
by sk (Curate) on Aug 08, 2005 at 06:46 UTC | |
Re: Regex question
by GrandFather (Saint) on Aug 08, 2005 at 06:46 UTC | |
Re: Regex question
by davidrw (Prior) on Aug 08, 2005 at 12:41 UTC |