A large one: +? says "match the shortest set of one or more of these", (so, a+? matches "a" in "aaaaaaaa"), while * says "match 0 or more of these"; a* matches "bob".
See Quantifiers in Regular Expressions in the Tutorials section of this site, or read perldoc perlre on your system.
More generally, see How to RTFM for information about where things like this are documented on your system.
perl -e 'print "How sweet does a rose smell? "; chomp $n = <STDIN>; $r
+ose = "smells sweet to degree $n"; *other_name = *rose; print "$other
+_name\n"'
| [reply] [d/l] [select] |
| [reply] |
Pay attention to the exact wording. * is a quantifier, it says "match ZERO OR MORE". There's no particular character it matches, it's just that any string you care to pass it satisfies the condition "has zero or more 'a's in it".
By itself, /a*/ isn't a very useful regular expression (nor, for that matter, is /a+?/ as opposed to simply /a/, because that will match a single 'a' and no more (the shortest string of one or more "a"s is one "a").
Try it :perl -e 'print "Yee haw!\n" if "bob" =~ /a*/'
Better yet, perl -e 'print "Yee haw!\n" if undef =~ /a*/'
HTH!
perl -e 'print "How sweet does a rose smell? "; chomp $n = <STDIN>; $r
+ose = "smells sweet to degree $n"; *other_name = *rose; print "$other
+_name\n"'
| [reply] [d/l] [select] |
Perhaps you were thinking of (a+)? vs. a*, which are technically the same. But a+? means "one or more of 'a', but match it as few times as possible", whereas a* means "zero or more of 'a', but match it as many times as possible".
There will be an exercise in LPRE which is to convert quantifiers back and forth.
japhy --
Perl and Regex Hacker | [reply] |
| [reply] [d/l] [select] |
this is incorrect, or at least misleading.
| [reply] |
Yes ! There More Than One Way To Do It, but Everything Is Different.
a* -> means zero character 'a' or more.
a+? -> means one character 'a' or more and the '?' is for none greedy (the smaller match of your regexp). That not the same as (a+)? which is optional here (because of '?').
I hope I am clear enough and that enlight you.
BoBiOne KenoBi ;) | [reply] |