Check if string starts with number using regular expression

I am writing a filebeat configuration when matching if the line starts with a number such as 03:32:33 (timestamp). I am currently doing this with

\d

But he will not be recognized if there is anything else that I should do. I am not particularly good / have experience with regular expressions. Help will be appreciated.

+4
source share
4 answers

The real problem is that filebeat does not support\d .

Replace \dwith [0-9]and your regex will work.

filebeat .

, , ^, .

+6
Regex: (^\d)

1st Capturing group (^\d)
    ^ Match at the start of the string
    \d match a digit [0-9] 
+3

You can use:

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

The ^ character matches the beginning of a line.

0
source

You can use this regex:

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


Demo


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) «?»
0
source

All Articles