javascript - JS regex match a word option with no backref -


let's have:

/(private|public|protected)\s+function\s+(\w+)\((.*)\)\s+{/gi 

to match beginning of function declaration. don't want use (private|public|protected) because ( , ) make backreference, can't use [ , ] because don't match full words.

basically, want function name $1 , arguments $2.

thanks all.

** edit **

per answer, used ?:

eg. /(?:private|public|protected)\s+function\s+(\w+)\((.*)\)\s+{/

you can use non-capturing group:

(?: ... ) 

from mdn documentation:

(?:x) matches 'x' not remember match. these called non-capturing parentheses. matched substring can not recalled resulting array's elements [1], ..., [n].


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -