英文:
Regular expression on negate of 4 digits appended with a hyphen without using negative lookahead
问题
我尝试了许多正则表达式的可能解决方案,以识别不以4位数字和连字符开头的行,而不使用负向前瞻。我正在尝试在filebeat中配置的正则表达式来识别不以年份和连字符开头的行。一个示例可以是2023-
。
一个使用负向前瞻的有效正则表达式是^((?!(^[0-9]{4}-$)).)*$
,可以用作开始识别问题的方法。有关如何在不使用负向前瞻的情况下完成的任何帮助?
英文:
I have tried with many possible solutions of regex to identify lines that do not start with 4 digits and a hyphen without using negative lookahead. The regex I am trying to configure in filebeat to identify lines that do not start with year and a hyphen. An example can be 2023-
.
One regex with negative lookahead which works is as ^((?!(^[0-9]{4}-$)).)*$
which can be used as a start to identify the problem. Any help regarding this that could be done without the negative lookahead.?
答案1
得分: 1
第一个选择项匹配一个字符串,其中前4个字符中至少有一个不是数字。第二个选择项匹配4个数字,后面不跟着连字符。
英文:
^(?:.{0,3}(?:[^\d\n]|$)|\d{4}(?:[^-\n]|$)).*
The first alternative matches a string where one of the first 4 characters isn't a digit. The second alternative matches 4 digits not followed by a hyphen.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论