0

如何使用正则表达式匹配结束标记之前缺少的句点 (.)?

为了让自己清楚,这里有一个示例:

样品需要匹配:

1. text</… ></tag> ---> Where </...> is any tag and can be multiple end tags

2. text</tag>  

不需要匹配的正确样本:

1. text.</...></tag>
2. text.</tag>

我想忽略这样的事情:

,</tag>   --> Where , can be any punctuation except period (.)

或者

,</...></tag>

我希望有人可以帮助我非常感谢!

4

3 回答 3

1

只需简单地使用[^\.]. 这将匹配任何内容,但. 在您的情况下,您需要使用[^\.>]</

于 2013-03-20T08:57:25.213 回答
0

这就是我对我的问题所做的:

([^.:;(or)(and)\!\)()>])(\</.*?\>)\</tag\>

这将匹配 end 之前没有句点 (.) 的文本:

text</otherEndTag>...</tag>

但是标点符号列表将被忽略:

: ; ! ) ( > , or , and
于 2013-03-22T02:50:48.220 回答
0

[,;:]将匹配除句点之外的任何标点符号。随意扩展(因为我不确定您是否想要撇号、引号、斜杠等字符)

您也可以通过使用[^,;:], where^代表 NOT in the character set 来否定它。

请参阅此内容以供参考。

于 2013-03-20T08:52:20.317 回答