Eclipse, regular expression search and replace
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.
Using ...
search = (^.*import )(.*)(\(.*\):)
replace = $1$2
...replaces ...
from checks import checklist(_list):
...with...
from checks import checklist
Blocks in regex are delineated by parenthesis (which are not preceded by a "\")
(^.*import ) finds "from checks import " and loads it to $1 (eclipse starts counting at 1)
(.*) find the next "everything" until the next encountered "(" and loads it to $2. $2 stops at the "(" because of the next part (see next line below)
(\(.*\):) says "at the first encountered "(" after starting block $2...stop block $2 and start $3. $3 gets loaded with the "('any text'):" or, in the example, the "(_list):"
Then in the replace, just put the $1$2 to replace all three blocks with just the first two.