Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Lookahead assertion

by BrowserUk (Patriarch)
on Oct 17, 2013 at 08:29 UTC ( [id://1058610]=note: print w/replies, xml ) Need Help??


in reply to Re: Lookahead assertion
in thread Lookahead assertion

When the engine sees that it should try again because of the /g, it steps one character past where last it tried.

This explains why the final . in BrowserUk’s solution is not strictly necessary

Indeed. The final '.' is not necessary with Perl's regex engine.

But many other regex libraries -- including some that claim to be Perl-compatible -- do not have this pragmatic deviation from the classical regular expression operation; hence it has become a habit with me to do this explicitly.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: Lookahead assertion
by talexb (Chancellor) on Oct 17, 2013 at 11:39 UTC

    Thanks for your reply .. and I checked, the final dot makes no difference in the result ..

    DB<6> @w3 = ( $foo =~ /(?=(\d{3}))/g ); DB<7> x @w3 0 123 1 234 2 345 3 456 4 567 5 679 6 790 DB<8> @w3 = ( $foo =~ /(?=(\d{3}))./g ); DB<9> !7 x @w3 0 123 1 234 2 345 3 456 4 567 5 679 6 790
    Good to know.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-24 20:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found