Find and replace with wildcards messing up formatting

Copper Contributor

Hi there,

 

I am doing a find and replace with wildcards to automatically replace parentheses within parentheses with square brackets:

 

for example: "Hi there (test (test 2))" should become "Hi there (test [test 2])"

 

It goes something like this:

Find: ([\(])([!\)]@)([\(])(*)([\)])(*)([\)])

Replace: \1\2[\4]\6\7

 

It works well, except that if anything like italics are involved, the square brackets don't match the formatting of the original brackets. For example:

"Hi there (test (test 2))" becomes "Hi there (test [test 2])"

 

Any obvious way to make sure that any new text inserted matches the formatting of the expression it replaces?

Cheers

 

Dan

 

0 Replies