var reg = new RegExp('\w');
var match = reg.exec('/hello/world/1');
console.log(match[0]);
The above log prints h. If you want to print hello, how do you do it?
var reg = new RegExp('\b\w+\b');
var match = reg.exec('/hello/world/1');
console.log(match[0]);
b
Match the beginning or end of a word.
var pattern = /hello/;
var str = "helloword";
console.log(pattern.exec(str)[0]);
Recommend you this website http://www.runoob.com/regexp/...
First w matches the literal value ww
matches the characters appearing in the word, such as a to z and _
If you need to match multiple
You can add *
at the end to indicate 0 or more
You can add +
at the end to indicate one or more