Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse regex search/replace not replacing after regex positive look-ahead?

Tags:

regex

eclipse

After I do a positive lookahead in eclipse 3.5, I am unable to do any sort of replace! Specifically, I put in any text string to replace the found string, and the text string is unable to be replaced. My positive lookahead is at the end of the line so as to include the positive lookahead text in the next search.

What's up? This is also a problem in the latest Aptana Studio, which is based on eclipse.

Example:

-Hello!  
I'm trying to match  
some stuff  
-Hello!  
Burbpaoiwjf  
paowijefpioj  
-Hello!  

Match pattern:

(?s)-Hello!(.*?)(?=-Hello!)

This will match, but I can't replace the matched text with anything.

like image 229
Stefan Kendall Avatar asked Aug 21 '09 15:08

Stefan Kendall


People also ask

What is positive look ahead in regex?

Positive lookahead: In this type the regex engine searches for a particular element which may be a character or characters or a group after the item matched. If that particular element is present then the regex declares the match as a match otherwise it simply rejects that match.

How do I search for a regular expression in Eclipse?

In Eclipse use the Ctrl + H shortcut to open the Search dialog. Select the File Search tab and check the Regular expression flag before entering your regular expression. You can also specify the file type and the scope for the search and replace operation.

Can regex replace?

They use a regular expression pattern to define all or part of the text that is to replace matched text in the input string. The replacement pattern can consist of one or more substitutions along with literal characters. Replacement patterns are provided to overloads of the Regex.

What is lookahead in regular expression?

Lookahead is used as an assertion in Python regular expressions to determine success or failure whether the pattern is ahead i.e to the right of the parser's current position. They don't match anything. Hence, they are called as zero-width assertions. Syntax: # Positive lookahead (?=<lookahead_regex>)


1 Answers

This is a known bug.

As a work-around, change your search pattern to:

(?s)-Hello!(.*?)-Hello!

And include

-Hello!

in your replace string.

like image 194
Jeremy Stein Avatar answered Oct 05 '22 01:10

Jeremy Stein