Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Using Look-ahead and Look-behind

by Roy Johnson (Monsignor)
on Dec 21, 2005 at 21:57 UTC ( #518444=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    /foo(?!.*foo)/
    
  2. or download this
    s/(?<=foo)/,/g; # Without lookbehind: s/foo/foo,/g or s/(foo)/$1,/g
    
  3. or download this
    s/(?<=look)(?=ahead)/-/g;
    
  4. or download this
    /foo  # Match starting at foo
     (         # Capture
    ...
     )         # End capture
     bar  # and ending at bar
    /x;
    
  5. or download this
    s/(?<=,        # after a comma,
        (?!        # but not matching
    ...
          (?=\d)   #   digit afterward
        )
      )/ /gx;      # substitute a space
    
  6. or download this
    s/(?<=,        # after a comma, but either
        (?:
    ...
          (?!\d)   #   not matching digit afterward
        )
      )/ /gx;      # substitute a space
    
  7. or download this
    print "$1\n" while /(?=(.*))/g;
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (14)
As of 2015-07-29 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls