Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find pattern HH:MM in Notepad++ with a regular expression

I’m using the latest version of Notepad++.

I have a text file and I want to delete all the characters except this one: (14:32).

The text if a list of lessons in a online course and I want to extract the time to sum all of them because I want to know how long it is.This is an example of the text:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Lecture 1.
    Programming robots (15:32)
    Understanding ROS (8:20)

I want to remove everything to get something like this:

(15:32)
(8:20)

I have tried these regular expressions:

^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$

/^(0?[1-9]|1[0-2]):[0-5][0-9]$/

But I can’t find anything with them.

How can I find this pattern in Notepad++?

Maybe, it could be easier find all the characters ([a-z][A-Z]) and replace them with nothing.

>Solution :

You can use

Find What: ^.*(\((?:[01]?[0-9]|2[0-3]):[0-5][0-9]\)).*
Replace With: $1

enter image description here

See the regex demo.

Details:

  • ^ – start of string
  • .* – any zero or more chars other than line break chars as many as possible
  • (\((?:[01]?[0-9]|2[0-3]):[0-5][0-9]\)) – Group 1:
    • \( – a ( char
    • (?:[01]?[0-9]|2[0-3]) – an optional 0 or 1 digit, and then any one digit, or 2 and then a digit from 0 to 3 range
    • : – a : char
    • [0-5][0-9] – minutes part (a digit from 0 to 5 and then any one digit)
    • \) – a ) char
  • .* – the rest of the line.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading