I'm having a bit of difficulty getting this one right and would appreciate some help please.
I want to replace lines like this
abc xyx etc [Text in square brackets]
with
Text in square brackets abc xyz etc
I can get fairly close with
Find: (.*)(\[[A-Za-z\\]+\]$)
Replace with: \2 \1
But so far I'm darned if I can remove the square brackets in the replaced string. I suppose I could simply apply two more steps to remove '[' and ']' respectively, but I'm sure it should be possible in one expression?
Note: The reason for the '\\' is that it's possible the bracketed string might contain '\' as well as 'simple' words. Ideally I'd like to allow for any special characters and numbers, but that's another complication I haven't tackled yet.
--
Terry, East Grinstead, UK
Grappling with an RE
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
To fix your regular expression, move the second set of parentheses so that they don't enclose the square brackets:
Find what: (.*)\[([A-Za-z\\]+)\]$
To allow for any special characters and numbers in the square brackets, change the [A-Za-z\\] to [^]]. This matches any character other than ], rather than just upper- and lower-case letters and backslashes. So:
Find what: (.*)\[([^]]+)\]$
Find what: (.*)\[([A-Za-z\\]+)\]$
To allow for any special characters and numbers in the square brackets, change the [A-Za-z\\] to [^]]. This matches any character other than ], rather than just upper- and lower-case letters and backslashes. So:
Find what: (.*)\[([^]]+)\]$