What is the use of
    ?= 
in perl regex
please tell the exact meaning and give some regex example.
            Asked
            
        
        
            Active
            
        
            Viewed 98 times
        
    1 Answers
1
            
            
        (?=...) 
is a positive lookahead, a type of zero-width assertion. What it's saying is that the match must be followed by whatever is within the parentheses but that part isn't captured.
Example:
.*(?=bar)
This pattern matches all the characters upto the string bar. When bar is detected then it stops matching. If a line contains more than one bar means it matches upto the last bar because .* does a greedy match.
 
    
    
        Avinash Raj
        
- 172,303
- 28
- 230
- 274
