< BACK

Javascript tips, tricks and code snippets

Regex - accessing matched groups

var str = "site build_version 0.3.7a";
var re = /(?:^|\s)build_(.*?)\s+(\S+)$/g;
var m = re.exec(str);
console.log(m[2]); // "0.3.7a"

See here for more detail.