Trizor is correct about the dot.

For some perhaps unneeded expansion, here's one possible regex, commented, in extended notation so you can see what you're really doing (and based on what I've inferred from your use of three captures, designed to collect the protocol, IP, and server_directory):

use strict; my $line = "http://127.0.0.1/home_dir"; if ($line =~ / # begin regex ( # begin Capture #1 http: # protocol ) # end Capture #1 \/+ # (discard) one (or more) forward slashes; impre +cise (127\.0\.0\.1) # Capture #2, including the dots IP \/ # (discard) one forward slash (home_dir) # Capture #3 (literal and simplistic) /x) # end regex, use extended syntax, end the if pr +edicate { print "$1\n"; print "$2\n"; print "$3\n"; } else { print "Bad RegEx\n"; } exit;

prints

http: 127.0.0.1 home_dir

Note that this is NOT a general solution, since I've used literals, liberally, from your example, and -- in the interest of simplicity -- without addressing such constructs as
{1,2}
a quantifier specifying either one or two of whatever it modfies <Post prandial update begins> or the use of alternate delimiters, both of which are illustrated here:

use strict; my $line = "http://127.0.0.1/home_dir"; if ($line =~ m% # begin regex - alternate delimiter ( # begin Capture #1 http: # protocol ) # end Capture #1 /{2,2} # (discard) exactly two forward slashes # note: no need to escape the "/" now, # can also be written as {2} in some cases ([\d.]{1,14}) # Capture #2, including literal dots IP / # (discard) one forward slash (\w{1,9}) # Capture #3, one-or-more (chars in range a-z O +R underline) %x) # end regex, use extended syntax, end the if pr +edicate { print "$1\n"; print "$2\n"; print "$3\n"; } else { print "Bad RegEx\n"; } exit;

So why did I even bother to mention that? Well, as you learn about regexen, you can make your tools more precise and more useful... and have a lot of fun doing so.

Jeffrey E. F. Friedl's "Mastering Regular Expressions" (O'Reilly) is the canon on the topic. It's a big mouthful, but one worth chewing through a bite at a time


In reply to Re: need to split URL string by ww
in thread need to split URL string by perl_geoff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.