Skip to content
Advertisement

how to write regex expression to find date and time

I am reading a file and looking for this string in the file.looking to capture the value(00:00:22) using regex.I have written regular expression but its not finding that value?

JavaScript

Advertisement

Answer

  1. Use the regex, \d{1,2}:\d{1,2}:\d{1,2} which means three combinations of 1 or 2 digits separated by :
  2. Use m.find() as the condition and m.group() to print the matched string.

Demo:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement