View Single Post
 
Old 12-11-2023, 03:44 AM
danhayter88 danhayter88 is offline Mac OS X Office 2021
Novice
 
Join Date: Dec 2023
Posts: 1
danhayter88 is on a distinguished road
Default Find and replace with wildcards but keep formatting

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
Reply With Quote