Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In eclipse, is it possible to use the matched search string as part of the replace string when performing a regular expression search and replace?

Basically, I want to replace all occurrences of

variableName.someMethod()

with:

((TypeName)variableName.someMethod())

Where variableName can be any variable name at all.

In sed I could use something like:

s/[a-zA-Z]+.someMethod()/((TypeName)&)/g

That is, & represents the matched search string. Is there something similar in Eclipse?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
700 views
Welcome To Ask or Share your Answers For Others

1 Answer

Yes, ( ) captures a group. You can use it again with $i where i is the i'th capture group.

So:

search: (w+.someMethod())

replace: ((TypeName)$1)

Hint: Ctrl + Space in the textboxes gives you all kinds of suggestions for regular expression writing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...