Regex to get words between ":" and "," in javascript -
I'm learning regex. I am trying to get the most correct regex for:
is input:
category: first, category: second, subject: math, subject: bio , Room: nine
expected output:
store first, second, math, bios, nine
Want the above output in a string; var s = ""; Whatever I have tried here:
(:) (. *) (,)
However, I should also want the last word
< / Div>
Use:
var again = /:(.*?) (: | $) / G; // `, | $ `: Match`,` or end of string Var str = 'class: first, category: second, subject: math, subject: bio, room: nine'; Var result = []; Match match; While ((match = re.x)! == faucet) results push (match [1]); result. Include (',') // = & gt; The use of 'first, second, math, bio, nine'.
:
var re = /: (. *?) (,) / G; Var str = 'class: first, category: second, subject: math, subject: bio, room: nine'; Str.match (re) .map (function (m) {return m.replace (/ [,:] / g, '');}). Join (',') // = & gt; 'First, second, math, bio, nine'
Comments
Post a Comment