arunhorne has asked for the wisdom of the Perl Monks concerning the following question:
Imagine I have a string that begins abc in the first three characters, but then ends with either def or xyz. If I wanted to write a regex to match these I would write the following... however, can someone show me how to use OR (|) such that it can go abc(def|xyz) as I can't seem to make it work :(
m/abcdef|abcxyz/
Surely I don't need to duplicate the abc bit twice as although it seems trivial here, in more complex apps it could lead to much bigger regexes?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using OR () in Regex
by larsen (Parson) on May 05, 2002 at 14:07 UTC | |
|
Re: Using OR () in Regex
by japhy (Canon) on May 05, 2002 at 14:17 UTC | |
by arunhorne (Pilgrim) on May 06, 2002 at 12:13 UTC | |
by japhy (Canon) on May 06, 2002 at 12:25 UTC |