Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace Whitespace before Brackets

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!

like image 219
David Yee Avatar asked Jan 21 '26 07:01

David Yee


1 Answers

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.

like image 57
Dhrubajyoti Gogoi Avatar answered Jan 23 '26 05:01

Dhrubajyoti Gogoi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!