我想找到以$开头的单词。
var s = "$hello, this is a $test $john #doe";
var re = /(?:^|\W)#(\w+)(?!\w)/g, match, matches = [];
while (match = re.exec(s)) {
matches.push(match[1]);
}上面的regex给出了以#开头的单词,但我不能使用相同的regex来查找以$开头的单词。
那么,我怎样才能找到以$开头的单词呢?
发布于 2018-04-24 04:45:31
请试试这个regex
var str = "$iPhone should be ab#le to complete and $delete items";
alert(str.match(/(^|\s)\$(\w+)/g).map(function(v){return v.trim().substring(1);}));
});https://stackoverflow.com/questions/49993590
复制相似问题