jquery - Regular expression gives invalid group error -


this question has answer here:

i trying find string between space , colon. have below regex expression giving me 'invalid group name' error (same in python also):

(?<content>[^ :]*:$) 

here regexdemo

same expression has no error in php demo.

javascript expression :-

var reg = new regexp("(?<content>[^ :]*):$", "g");` 

can tell me why should this?

edit:

sample input:

defvariable   変数名:配列「n] defvariable  変数名:string defvariable   変数名:int defvariable   変数名:decimal defvariable   変数名:日付 defvariable   変数名:時間 

sample output:

could match 変数名: each line instead of 変数名 character come.

your regex incorrect :

(?<content>[^ :]*:$) 

a (?<group>) notation doesn't exist in javascript. (numbered group), (?:non capturing) , lookarounds. if understand correctly, need :

\s([^ :]*):$ 

see demo here.