[Nottingham] Perl Regular Expression Query.
Paul Sladen
nottingham at mailman.lug.org.uk
Fri Jan 17 15:36:01 2003
On Fri, 17 Jan 2003, Robert Postill wrote:
> I've been at this with the question marks because I was told the regex
> engine would swallow the intermediate @ signs. So thanks for that.
After a character, [..] set, or (block) you can use:
? optionally match this
* match zero of more of this
+ match one of more of this
{,} match upto, less than, more than, or an exact number of
Therefore the Question Mark and Star don't make sense together; if you
don't want the fields between the `@' to contain `@' themselves (non-greedy
matching), you can do:
/@([^@]+)@/
Which means that with "@foo@bar@" you'll end up with just the "foo" and not
"foo@bar". The brackets () are selecting what you'll get out in the
positional matches afterwards.
-Paul
--
Nottingham, GB