I have a long text file with lot's of brackets like [abc ], [U12 3]. I can find them using:
RegExMatch(myTxt, "i)\[[0-9a-zA-Z\-_\s]*\]", Brac).
How can I use RegExReplace to remove the spaces inside of them?
"lot's of brackets like [abc ], [U12 3]" to: " lot's of brackets like [abc], [U123]"
RegExReplace
- oldbrother
- Posts: 273
- Joined: 23 Oct 2013, 05:08
Re: RegExReplace
Code: Select all
str := "lot's of brackets like [abc ], [U12 3]"
MsgBox, % RegExReplace(str, "\[[^\]]*?\K (?=.*])")
- oldbrother
- Posts: 273
- Joined: 23 Oct 2013, 05:08
Re: RegExReplace
Thank you boiler,
Sorry for my example. The spaces can be more than one, or in multiple places within a pair of brackets:
Sorry for my example. The spaces can be more than one, or in multiple places within a pair of brackets:
Code: Select all
str := "lot's of brackets like [abc ], [U 12 3], something like this [ D00 K]."
Target:
str := "lot's of brackets like [abc], [U123], something like this [D00K]."
Re: RegExReplace
It could be done with a loop, which would just keep repeating the above until it no longer replaces anything, but maybe someone will have a clever RegEx-only approach.
-
- Posts: 4325
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: RegExReplace
Code: Select all
str := "lot's of brackets like [abc ], [U 12 3], something like this [ D00 K]."
MsgBox, % RegExReplace(str, "\s(?=[^[]*?])")
- oldbrother
- Posts: 273
- Joined: 23 Oct 2013, 05:08
Re: RegExReplace
It works perfectly! Thank you all!