On Fri, Jul 06, 2012 at 06:59:00PM +0100, Adam J. Gamble wrote:
> Dear All,
> 
> I'm taking a (highly belated) first look at Perl today. From a background
> in Python, I'm coming to Perl, primarily out of curiosity with what it can
> do with regular expressions.

Welcome!

> To get to the point— is it possible to match a character class with a
> repeater that requires an exactly *n* OR *m* matches, rather than the
> traditional *{n, m}*. I've taken a look at
> http://perldoc.perl.org/perlrequick.html#Using-character-classes, which
> implies this wouldn't be possible? But, putting faith Perl's reputation for
> inherent quirkiness... if possible, I'd love to know what a solution would
> look like?

You're correct that there is no way to do this directly, but if you look
at the section just below (Matching this or that) you can see the basis
for a solution.

So, to match either three or five "a"s for example, you could do this:

  /^(?:a{3}|a{5})$/

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to