Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: how to do match www.jkghfdjbh.org from $li?

by AnomalousMonk (Archbishop)
on Jun 11, 2013 at 11:18 UTC ( [id://1038235]=note: print w/replies, xml ) Need Help??


in reply to Re: how to do match www.jkghfdjbh.org from $li?
in thread how to do match www.jkghfdjbh.org from $li?

Further to davido's point about alternation:
Because it's a point that often escapes people (it's escaped me often enough), I want to emphasize that the effective low precedence of the  | (alternation) regex operator means that the  [A-Z].[a-z] portion of the OPed regex matches independently of the rest of that particular regex. E.g., after fixing the  // delimiter confusion, but leaving the  . (dot) matching as it was:

>perl -wMstrict -le "my $li = 'foo'; ;; print qq{matched '$&' in '$li'} if $li =~ m{http://www.[a-z]|[A-Z].[a-z]}i; " matched 'foo' in 'foo'

NB: Don't get into the habit of using the  $& $` $' special matching variables in your regexes. See the paragraph in perlre that begins "WARNING: Once Perl sees that you need one of $&, $`, or $' anywhere in the program ..." for a discussion of the cost of using them, and also the following paragraph for a workaround available in Perl version 5.10+. Also see the discussion of these variables in perlretut for workarounds using substr that can be used pre-5.10.

Replies are listed 'Best First'.
Re^3: how to do match www.jkghfdjbh.org from $li?
by davido (Cardinal) on Jun 11, 2013 at 15:11 UTC

    Lol. I totally missed the /http//:...../ delimiter bug. It starts looking like an intentional attempt to get it wrong just so we will jump around like our hair is on fire trying to fix it. ...because there really is nothing that is right within it. An honest attempt to get it right would contain at least one portion of the RE that isn't a bug. ;)


    Dave

      You missed it, because it was not in the question initially. I really hate it, when the question is altered after receiving the first answers. Usually makes the answers looking silly as they point to issues that are not present in the question.

        oOOh! Well that explains why I recommended URI::Find::Schemeless rather than URI::Find.


        Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1038235]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-19 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found