我想找到一段文本中的所有#tags
(使用javascript)并使用它们。正则表达式 myString.match(/#\w+/g)
有效,但我也得到了 #。如何只获取没有 # 的单词?
最佳答案
你可以这样做:
var code='...';
var patt=/#(\w+)/g;
var result=patt.exec(code);
while (result != null) {
alert(result[1]);
result = patt.exec(code);
}
关于javascript - 使用 javascript 匹配存储正则表达式的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8820387/