Reputation: 1463
I've a concatenated file in js where I have functions starting with underscore and some other who are not. In this file I'd like to match only functions starting with underscore regardless if the function is quoted or not.
How can I do that?
This is matching only one or another, not both in: test._function1 = function(){} "ng-click="test._function1()""
/(_)[^" ]+|_/
Upvotes: 1
Views: 581
Reputation: 199
You Definitely Require the /g Modifier.
The Regex you Provided Will Match all _ Characters in your string this could cause some issues. Also its not needed to add another group.
Instead of using this.
/(_)[^" ]+|_/g
you could use this
(_)[^" ]+/g
Live demo: https://regex101.com/r/sB7kX2/1
Lastly it might be better to add a better prefix if Possible. This Should limit the chances of untended matches.
(_myFunction)[^" ]+/g
Upvotes: 4