进行正则表达式以匹配所有不以时间戳开头的行
Can anybody explain what the correct Java regex is to match all lines that don't start with timestamp [0-9]{4}-[0-9]{2}-[0-9]{2}
?
I am trying to use ^(^[0-9]{4}-[0-9]{2}-[0-9]{2})
but it doesn't work.
任何人都可以解释正确的Java正则表达式是什么,以匹配所有非以时间戳记 我正在尝试使用开头的行。 0-9] {4}-[0-9] {2}-[0-9] {2} code>? p>
^ (^ [0-9] {4}-[0-9] {2}-[0-9] {2}) code>,但它不起作用。 p>
div>
Your ^(^[0-9]{4}-[0-9]{2}-[0-9]{2})
pattern matches a string starting with the pattern you defined (the ^
here just matches the start of a string).
In Go lang, the regex engine does not support lookarounds, and thus it is difficult to create a readable regex that would do the required job.
I suggest you remove all lines that match your pattern
(?m)\s*^[0-9]{4}-[0-9]{2}-[0-9]{2}.*
(see demo) and then split the result with line breaks to get the lines that did not match the pattern.