Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Re: Regex (lookahead) Confusion

by ChrisR (Hermit)
on Feb 05, 2004 at 22:01 UTC ( [id://326905]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Regex (lookahead) Confusion
in thread Regex (lookahead) Confusion

So let's see if I understand this and please correct me if I'm wrong.

The ?: means that the parens are just for grouping and will load any matches into $1, $2, etc.
Then the character class in parens
and then the lookahead...
?! means that it is a negative lookahead
.* means any character 0 or more times (very greedy)
\1 is related to the character matched from the character class
It's the .* that is throwing me off. To me, that looks like it would match a single character repeated any number of times but not separated duplicate characters. I just don't understand it ... yet. I will keep looking.
  • Comment on Re: Re: Re: Regex (lookahead) Confusion

Replies are listed 'Best First'.
Re: Re: Re: Re: Regex (lookahead) Confusion
by allolex (Curate) on Feb 05, 2004 at 22:10 UTC

    s/will load/will not load/, right?

    The .* is saying there can be any number of characters in the string between the first match (the character class) and the backreference (\1) match, from zero (two characters next to each other) on up...

    Say out first match was 'a', then 'a' is also referred to in \1. Then we have a.*a: aa,  a.a,  a..a,  a...a,  a....a, etc. And its a negative lookahead, so if any one of those combinations matches, the regex will fail.

    --
    Allolex

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found