Skip to content
Prev 374695 / 398503 Next

removing part of a string

Hello,

Ulrik's way is simpler therefore better. I would use it, not mine.

As for an explanation of mine, here it goes.

1) Parenthesis are meta-characters and must be escaped if you want to 
match them:

\\(  and  \\)

2) You want to keep them so I used groups, i.e., put what you want 
between parenthesis (these serve a different purpose, they will not be 
matched).

(\\()  and (\\))  are group \1 and group \2

3) remove everything between the two groups:

.*

4) combine all:

(\\().*(\\))  is the pattern to match

The replacement is \\1\\2

Ulrik's pattern is simpler, no groups, just \\( and \\) with .* between 
them, replaced by ()

Hope this helps,

Rui Barradas
On 5/21/2018 3:00 PM, Ulrik Stervbo wrote: