Regex is capturing the whole string

Posted by M28 on Stack Overflow See other posts from Stack Overflow or by M28
Published on 2010-04-06T23:19:13Z Indexed on 2010/04/06 23:23 UTC
Read the original article Hit count: 389

Filed under:
|

I am using the following regex:

(public|private +)?function +([a-zA-Z_$][0-9a-zA-Z_$]*) *\\(([0-9a-zA-Z_$, ]*)\\) *{(.*)}

To match the following string:

public function messenger(text){
sendMsg(text);
}
private function sendMsg(text){
alert(text);
}

(There is no line breaks in the string, they are converted to whitespaces before the regex runs)

I wanted it to capture both functions, but it is capturing: $1: "" $2: "messenger" $3: "text" $4: " sendMsg(text); } private function sendMsg(text){ alert(text); "

By the way, I am using Javascript.

© Stack Overflow or respective owner

Related posts about regex

Related posts about JavaScript