使用jquery正则表达式在两个匹配的字符之间获取多个字符串

时间:2014-09-22 05:23:55

标签: jquery regex

&#34;我期待五百美元<Sample500>。和新括号<600>下一个< Sample>&#34;。

在上面的句子中我想得到&#34;&lt;&#34;之间的字符串。和&#34;&gt;&#34;比如["Sample500","600"," Sample"]

为此我使用正则表达式,如 - &gt;

"I expect five hundred dollars <Sample500>. and new brackets <600> next <Sample>".match(/\<<[^>]+>\>/g)

请提供有效的正则表达式

2 个答案:

答案 0 :(得分:2)

<([^>]*)>

你可以尝试一下。参见演示。

http://regex101.com/r/kM7rT8/1

答案 1 :(得分:1)

这将为您解决问题:

var s = "I expect five hundred dollars <Sample500>. and new brackets <600> next <Sample>";
var matches = [];
s.replace(/<(.*?)>/g, function(g0,g1){
  matches.push(g1);
});
console.log(matches);