【发布时间】:2017-12-16 06:12:10
【问题描述】:
考虑以下字符串:
08/07/2017Peter Praet: Interview with De StandaardInterview with Peter Praet, Member of the Executive Board of the ECB, conducted by Pascal Dendooven and Goele De Cort on 3 July 2017, published on 8 July 2017ENGLISH\n\t\t\t\t\t\t\tOTHER LANGUAGES\n\t\t\t\t\t\t\t(1)\n\t\t\t\t\t\t\t+\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tSelect your language\n\t\t\t\t\t\t\t\n\t\t\t\t\t\tNederlandsNL07/07/2017Benoît Cœuré: Interview with Le Monde and La StampaInterview with Benoît Cœuré, Member of the Executive Board of the ECB, conducted by Marie Charrel (Le Monde) and Alessandro Barbera (La Stampa), on 3 July, published on 7 July 2017ENGLISH"
我想把里面的两句话提取出来,分别是:
"08/07/2017Peter Praet: Interview with De StandaardInterview with Peter Praet, Member of the Executive Board of the ECB, conducted by Pascal Dendooven and Goele De Cort on 3 July 2017, published on 8 July 2017ENGLISH""NederlandsNL07/07/2017Benoît Cœuré: Interview with Le Monde and La StampaInterview with Benoît Cœuré, Member of the Executive Board of the ECB, conducted by Marie Charrel (Le Monde) and Alessandro Barbera (La Stampa), on 3 July, published on 7 July 2017ENGLISH"
我尝试使用[\w]+(?!\\t),但这会捕获t(1 中的t 以及其他内容。
这里的正确语法是什么? 谢谢!
【问题讨论】:
-
您使用哪种编程语言?因为他们的
regexpr每个都略有不同。另外,你是否试图从这个字符串中提取东西?或者正则表达式也必须适用于其他类似事件? -
尝试
\w{4,}而不是[\w]+。这将消除三个或更少字符的匹配,而且我很确定\w已经是一个字符类:不需要括号。 -
在 Python 中,您可以在制表符和换行符上执行
re.split并过滤掉少于 20 个字符的任何内容。 -
这就像去射击场磨练你的剑术 :) 找到一个真正受益于纯正则表达式解决方案的问题并磨练出来。
-
给你,分开这个
r'(?:\\[\\ntr])+(?:(?:(?!\\[\\ntr]).)*\\[\\ntr])*'regex101.com/r/lNv8VO/1