I'm trying to learn regular expressions and I would like all whitespaces before the open parenthesis to be replaced with an underscore using Notepad++ regular expression search and replace.
Currently, my regular expression only replaces a space if it is immediately before the open parenthesis.
Before: FIRST MIDDLE LAST(" ", " ")
Expected: FIRST_MIDDLE_LAST(" ", " ")
My attempted regular expression: \s+(?=\()
\s+ matches one or more white spaces
(?=\() is a positive look ahead using \( (open parenthesis) as the character.
Can anyone please explain what the correct regular expression should be? Thanks in advance!
If I understood it correctly this should work for you:
Find \b\s+(?=.*?\() Replace: _
ie. all whitespaces following a word boundary, which is again followed by, but not a part of the selection, a couple of characters until the first occurrence of a opening bracket.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With