Regex 使用正则表达式检查字符串是否以数字开头

Regex 使用正则表达式检查字符串是否以数字开头,regex,logstash,filebeat,Regex,Logstash,Filebeat,如果一行以03:32:33(时间戳)这样的数字开头,则在匹配时,我正在编写filebeat配置。我现在正在做这件事- \d 但它没有得到承认,还有什么我应该做的。我对正则表达式不是特别好/有经验。非常感谢您的帮助。您可以使用: Regex: (^\d) 1st Capturing group (^\d) ^ Match at the start of the string \d match a digit [0-9] ^\d{2}:\d{2}:\d{2} 字符^与行首匹

如果一行以03:32:33(时间戳)这样的数字开头,则在匹配时,我正在编写filebeat配置。我现在正在做这件事-

\d
但它没有得到承认,还有什么我应该做的。我对正则表达式不是特别好/有经验。非常感谢您的帮助。

您可以使用:

Regex: (^\d)

1st Capturing group (^\d)
    ^ Match at the start of the string
    \d match a digit [0-9] 
^\d{2}:\d{2}:\d{2}
字符^与行首匹配。

真正的问题是filebeat

[0-9]
替换
\d
,正则表达式将正常工作

我建议你去看一下档案室


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

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

^([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) «?»