I have this regex https://regex101.com/r/wRBBAz/1
JavaScript
x
2
1
(?<=s|^|.)[^ .]+(?=s*(())
2
Testing with input
JavaScript
1
3
1
test1 { }
2
test2();
3
I specified start of line (^) in lookaround so I don’t understand why it selects
JavaScript
1
3
1
}
2
test2
3
instead of only
JavaScript
1
2
1
test2
2
Advertisement
Answer
The problem is that [^ .]
matches any char but a space and a dot, that is, it matches line break chars.
You can use
JavaScript
1
2
1
(?<![^.s])[^s.]+(?=s*(())
2
See the regex demo
Details
(?<![^.s])
– a negative lookbehind that matches a location that is either at the start of string or immediately preceded with a dot or whitespace[^s.]+
– any one or more chars other than whitespace and.
(?=s*(())
– a positive lookahead making sure there is zero or more whitespces and then a(
(captured into Group 1) immediately to the right of the current location.