RE: What exactly is this simple regex doing?

From: B. Fongo (perl_at_fongo.de)
Date: 04/16/04


To: "'Wiggins d Anconia'" <wiggins@danconia.org>, <beginners@perl.org>
Date: Fri, 16 Apr 2004 18:20:54 +0200

Thanks for the small tutorial - but I must admit that I can only see
(according to your explanation) the regex to be matching anything except
a dot. So substituting them should return only 1 or more dots. But that
isn't what we get here. You're by saying that the dot in a class is not
a special qualifier.

Oh! How I wish I could understand it. :-) I think I need to go back to
learn some more regexs.

||> -----Original Message-----
||> From: Wiggins d Anconia [mailto:wiggins@danconia.org]
||> Sent: Friday, April 16, 2004 5:40 PM
||> To: B. Fongo; beginners@perl.org
||> Subject: Re: What exactly is this simple regex doing?
||>
||> Please bottom post....
||>
||> >
||> > This regex by Rob is working alright, but can't follow exactly how
it
||> > truncates an absolute url from first character to the one before
the
||> > dot.
||> >
||> > It returns (.domain4you.com from http:://www. domain4you.com.)
exactly
||> > what is expected, but I can't easily understand it.
||> >
||> > Please I'm not pulling anyone's leg. So just explain it if you
can.
||> >
||> > (.domain4you.com from http:://www. domain4you.com.)
||> >
||> >
||> > foreach (@domains) {
||> > my $name = $_;
||> > $name =~ s/^[^\.]+//;
||> > print $name;
||> > }
||>
||> The initial ^ says to start matching at the beginning of the string.
||>
||> [] defines a character class, so we are going to match against
||> characters in the class.
||>
||> In this case the ^ *because it is the first character* of the class
||> causes the class to be negated, aka we are going to match any
character
||> *not* in the class. The class is a \ and a . though I suspect that
||> should just be a . because I believe dot inside a class is not
special.
||>
||> The + says one or more of the characters matched by the class.
||>
||> So it is really saying match one or more characters that are not a
dot
||> starting at the beginning of the string. Or, match everything up
until
||> the first dot.
||>
||> http://danconia.org



Relevant Pages

  • Re: regex, negations, grep, find and replace (a few questions)
    ... I do not know much regex. ... But it seems as if you define each character ... be aware that different tools may use slightly different syntaxes for the same regular expressions. ... expresion" might mean "matching everything not matching the regular expression" or, in other words, removing everything matching the regexp. ...
    (alt.os.linux)
  • Re: What exactly is this simple regex doing?
    ... I see people have explained the regex itself but not how it's doing ... It's actually removing everything up until a dot is found ... string eg http:://www.domain4you.com ... means match any character as many times as possible until the next ...
    (perl.beginners)
  • RE: What exactly is this simple regex doing?
    ... > the regex to be matching anything except ... > a dot. ... So substituting them should return only 1 or more dots. ...
    (perl.beginners)
  • what does a dot "." mean in regex, when it is in brackets?
    ... I thought a dot meant any character in regex, ... Prev by Date: ...
    (alt.php)
  • Re: Phiw and Ben
    ... is there any character worth their salt aside from Dot? ... worth watching, but utterly marginalized. ... Not for a second would Dot refuse to take care of her ailing hubby at home - it goes against everything we've ever known about her character over the last 23 years. ...
    (rec.arts.tv.uk.eastenders)