两个连续数字的正则表达式否定

Regex negation for two consecutive numbers

我正在尝试创建一个让我大吃一惊的正则表达式。 当我有两个连续的数字时,如何使下面的正则表达式取反?

/^([\p{L}\p{N}\. ]+)(, ?| )([0-9-]+[a-z]?)(, ?| |$)(.*)/iu

有效示例:

Text Text 123 anything
Text Text, 123, anything
Text Text 123B anything
Text Text, 123B, anything
Text 123 anything
Text 123B anything
Text, 123, anything
Text, 123B, anything
987 123 anything
987 123B anything
987, 123, anything
987, 123B, anything

(必须)无效的例子:

Text Text 456 123 anything
Text Text, 456, 123, anything
Text Text 456 123B anything
Text Text, 456, 123B, anything
Text 456 123 anything
Text 456 123B anything
Text, 456, 123, anything
Text, 456, 123B, anything
987 456 123 anything
987 456 123B anything
987, 456, 123, anything
987, 456, 123B, anything

但是正如你们所见,上面的所有示例都适用于我的正则表达式:https://regex101.com/r/6t5Oq5/4

要求:第一组可以有字母或数字。第二组可以有数字或数字后跟一个字母,第三组可以有任何东西。所有组可以用逗号或 space 分隔。所有字母和数字都可以是任意大小。 字符串中不能有连续的数字,除非数字在第一组或最后一组(任何)。

最好的方法是什么?

不能 100% 确定您的要求规则,但这里的正则表达式匹配第一个但不匹配第二个块:

/^([a-z0-9]+,? )([0-9]+[a-z]?,? )([a-z0-9]+)$/

此处演示:http://regexr.com/3gjd7

根据您发布的内容,使用此模式 ^(\S+)(?=[^\d\r\n]+\d+[^\d\r\n]+$).* Demo

^                       # Start of string/line
(                       # Capturing Group (1)
  \S                    # <not a whitespace character>
  +                     # (one or more)(greedy)
)                       # End of Capturing Group (1)
(?=                     # Look-Ahead
  [^\d\r\n]             # Character not in [\d\r\n] Character Class
  +                     # (one or more)(greedy)
  \d                    # <digit 0-9>
  +                     # (one or more)(greedy)
  [^\d\r\n]             # Character not in [\d\r\n] Character Class
  +                     # (one or more)(greedy)
  $                     # End of string/line
)                       # End of Look-Ahead
.                       # Any character except line break
*                       # (zero or more)(greedy)