如果你看这个文字:
FIRST TEXT (IF CAPS AND IF IT ENDS WITH A PERIOD) SHOULD BE EXCLUDED. Here comes all the text we want to grab. And the ONLY problem with our current regular expression is that it also includes the period and space in front of this text. Does anyone know how to fix it so we grab from "Here comes..." and not ". Here comes..."? Thank you.
我当前的正则表达式如下所示:(?![A-ZÆØÅ!''/ 0-9 \ s()] + [。])[^ =] *
答案 0 :(得分:0)
答案 1 :(得分:0)
点和空格是匹配的,因为您的超前模式仅与点匹配。为确保您的匹配不以.
+空格开头,您可以使用它们(如果存在)。在这种情况下,可选的非捕获组非常方便:
(?![A-ZÆØÅ!´'\/0-9\s()]+[.])(?:\.\s*)?\K[^=]+
^^^ ^^
或者,如果您的正则表达式引擎不支持\K
匹配重置运算符,请使用捕获组:
(?![A-ZÆØÅ!´'\/0-9\s()]+[.])(?:\.\s*)?([^=]+)
^ ^
请参阅regex demo。