On Fri, Sep 4, 2009 at 04:08, Noah Garrett Wallach<noah-l...@enabled.com> wrote:
>
> Hi there,
>
> is there any way to search for the following text?  In some cases the text
> that I am search could be
>
> "one-two-three-"
>
> or sometimes the text could be
>
> "one-two-"
>
> what is a nice easy why to parse the above - quotes not included.
snip

What you are looking for is quantifiers.  Quantifiers state how many
times the preceding pattern must match:

if (/^one-two-(?:three-){0,1}$/} {
    print "matched\n"
}

In that example the quantifer {0,1} says that the pattern (?:three-)
should be between zero and one times.  This is a common enough
quantifier that it has gotten a shortcut:

if (/^one-two-(?:three-)?$/} {
    print "matched\n"
}

Other shortcuts are + (for {1,}, i.e. one or more) and * (for {0,},
i.e. zero or more).

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
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