正则表达式匹配排除某些模式

时间:2017-12-06 07:31:14

标签: javascript regex

我有一个文字
<1.1.1>This is para one with <1.1.2>more than five words. I <1.1.3>is trying to test grammar <1.1.4>API with this. <1.2.1>This are para two, let's <1.2.2>test it. I am using <1.2.3>it <1.3.1>​

在此我想要匹配 is para one with more than five words. I is trying to test grammar API with this. T

我试过一个reg ex (?:(\<([0-9]*\.[0-9]*\.[0-9]*)\>))(This is para one with more)

我想要的结果如下: is para one with <1.1.2>more than five words. I <1.1.3>is trying to test grammar <1.1.4>API with this. <1.2.1>T 但是无法找到解决方案,我如何能够递归地匹配排除单词。

1 个答案:

答案 0 :(得分:3)

你可以做到

&#13;
&#13;
let str = "<1.1.1>This is para one with <1.1.2>more than five words. I <1.1.3>is trying to test grammar <1.1.4>API with this. <1.2.1>This are para two, let's <1.2.2>test it. I am using <1.2.3>it <1.3.1>​";

str = str.replace(/<\d\.\d\.\d>/g, '');

console.log(str);
&#13;
&#13;
&#13;