Just another Perl shrine | |
PerlMonks |
Re: Pattern Matchby Athanasius (Archbishop) |
on Jun 08, 2017 at 07:51 UTC ( [id://1192332]=note: print w/replies, xml ) | Need Help?? |
Hello Nansh,
This can’t be exactly true, since a regex containing Fruits (note the literal character s) will never match Fruit{ Apple } in which the s is missing. Perhaps this was merely a typo; otherwise, you need to make the s optional: Fruits?. Speaking of ?, in its current position in the regex — (.*)? — it acts as a quantifier specifying zero or one repetitions of the preceding expression. In the present case this adds nothing, since the expression it quantifies already specifies zero or more characters. More likely, you were looking to make the * quantifier non-greedy, in which case the ? needs to go inside the capturing parentheses:
Output:
Hope that helps,
In Section
Seekers of Perl Wisdom
|
|