I would like to remove one or more spaces before and after any parentheses. Following this post where the issue has been solved for PHP with the following regex
(?<=[([]) +| +(?=[)\]])
now I would like to do the same in Javascript but Javascript regex engine does not have the same lookahead and lookbehind as PHP. I managed to make the following regex at least work in Javascript but it removes all spaces:
?![([]) +| +(?=[)\]])
See Regex101 test.
Given string:
This is ( a sample ) [ string ] to play with
Expected result:
This is (a sample) [string] to play with