17

如果一行以 03:32:33 (时间戳)之类的数字开头,我在匹配时正在编写 filebeat 配置。我目前正在这样做——

\d

但它没有得到认可,还有什么我应该做的。我不是特别好/有正则表达式的经验。帮助将不胜感激。

4

4 回答 4

20

真正的问题是filebeat 不支持\d.

替换\d[0-9],您的正则表达式将起作用。

我建议你看看 filebeat 的Supported Patterns

另外,请确保您使用过^,它代表字符串的开头。

于 2016-05-30T18:16:06.603 回答
5

您可以使用此正则表达式:

^([0-9]{2}:?){3}


演示


Assert position at the beginning of the string «^»
Match the regex below and capture its match into backreference number 1 «([0-9]{2}:?){3}»
   Exactly 3 times «{3}»
      You repeated the capturing group itself.  The group will capture only the last iteration.  Put a capturing group around the repeated group to capture all iterations. «{3}»
      Or, if you don’t want to capture anything, replace the capturing group with a non-capturing group to make your regex more efficient.
   Match a single character in the range between “0” and “9” «[0-9]{2}»
      Exactly 2 times «{2}»
   Match the character “:” literally «:?»
      Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
于 2016-05-30T18:21:30.940 回答
4
Regex: (^\d)

1st Capturing group (^\d)
    ^ Match at the start of the string
    \d match a digit [0-9] 
于 2016-05-30T17:56:20.717 回答
0

您可以使用:

^\d{2}:\d{2}:\d{2}

字符 ^ 匹配行首。

于 2016-05-30T17:57:10.147 回答