Javascript匹配不包括

时间:2015-05-07 15:23:14

标签: javascript regex match

字符串:

<row>1</row>
<row>2</row>

正则表达式:

<row>([\s\S]*?)<\/row>/gm

结果:

["<row>1</row>", "<row>2</row>"]

期望的结果

["1", "2"]

1 个答案:

答案 0 :(得分:0)

以下是一个示例:http://jsfiddle.net/zgdksaax/

var pattern = /<row>([\s\S]*?)<\/row>/gm;
var string = "<row>1</row><row>2</row>";
console.log(string.replace(pattern, "$1").split("")) // ["1", "2"]