$Bill Luebkert <[EMAIL PROTECTED]> wrote:
> Nex6 wrote:

> > if ($slurp =~ /"defaultusername"="(.+)"/i) {
> 
> "(.+)" should probably be "(.+?)" to limit the match to the
> shortest path unless you know there are no more "s after it.

In this case it makes no difference, but in general a negated 
character class is less likely to lead to unexpected matching 
than a nongreedy modifier is.  That is, I'd use '([^"]+)' 
rather than '(.+?)'.  To see why I prefer the negated character 
class, consider a regex like

   /<a href="(.*?)">/

Because of the nongreediness, it's true that the matching won't 
get completely out of control, but suppose the string being 
matched against is

   <a href="/whatever/" target=_blank>Link <img 
src="abc.gif"></a>

Now the captured string is '/whatever/" target=_blank>Link <img 
src="abc.gif', which presumably was not intended.  With 
'([^"]+)', the match would have failed, which may have been the 
intent.  If not, the failure should at least indicate there may 
be a problem with the regex.

-- 
Keith C. Ivey <[EMAIL PROTECTED]>
Washington, DC

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to