Hi guys,
 
I could able to understand the quantifiers. But still stuck with one 
confusion.if dot operator is used with quantifiers.
 
ex: my string is $_="thiiiis is my first regular expression";
 
please explain the  below  questions with answer.
1)thi.*? 
2)thi.+?
3)thi.+?s
4)thi.*?s
 
 
Thanks in advance.
 
 
Best Regards,
chandan.


--- On Thu, 15/7/10, Chas. Owens <chas.ow...@gmail.com> wrote:


From: Chas. Owens <chas.ow...@gmail.com>
Subject: Re: Query on Qunatifiers
To: "Thomas Bätzler" <t.baetz...@bringe.com>
Cc: "Beginners Perl" <beginners@perl.org>, "Chandan Kumar" 
<chandan_28...@yahoo.com>
Date: Thursday, 15 July, 2010, 2:08 PM


On Thu, Jul 15, 2010 at 03:22, Thomas Bätzler <t.baetz...@bringe.com> wrote:
snip
> In RE, a "." by itself is the atom that matches any one character.
>
> The quantifiers mean:
>
> "?" 0 or 1 occurences of the previous expression.
> "+" 1 or more occurrences of the previous expression (greedy match).
> "*" 0 or more occurrences of the previous expression (greedy match).
> "*?" 0 or more occurrences of the previous expression (parsimonious match).
> "+?" 1 or more occurrences of the previous expression (parsimonious match).
>
> The difference between greedy and parsimonious matching is that in a greedy 
> match,
> the longest possible match will be tried first whereas in a parsimonious 
> match,
> the shortest match will be tried first.
snip

In addition to the named quantifiers there are the generic quantifiers:

"{n}" match exactly n occurrences of the previous expression (greedy match).
"{n,}" match n or more occurrences of the previous expression (greedy match).
"{n,m}" match between n and m occurrences of the previous expression
(greedy match).
"{n}?" match exactly n occurrences of the previous expression
(parsimonious match).
"{n,}?" match n or more occurrences of the previous expression
(parsimonious match).
"{n,m}?" match between n and m occurrences of the previous expression
(parsimonious match).

You can create the others from the generics:

"?" is "{0,1}"
"+" is "{1,}"
"*" is "{0,}"

It is important to note that "or more" is not really unlimited.  It is
currently limited to 2,147,483,647 occurrences.  Of course, in order
to run into that limit you must have, at minimum, a string that is 2
gigabytes in size.

perl -Mre=Debug,EXECUTE -e '/.*/'

Matching REx ".*" against ""
   0 <> <>                   |  1:STAR(3)
                                  REG_ANY can match 0 times out of 2147483647...
   0 <> <>                   |  3:  END(0)
Match successful!

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


Reply via email to