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

How to match lines with a rule

I want to search for all lines that:

  • start with a numeric repeat (one or several times) which is not followed by dot and a whitespace character

Given Lines

1. TEST 1 : DataLogFile
11. TEST 2 : Inter Citro File
111. TEST 3 : Inter Citro File
111.TEST4 : Match this

Expected Result

Matched only last line

111.TEST4 : Match this

Regex

I try with regex ^[0-9]+(?!. ).* to match normaly only the last row because there is no whitespace character after the dot.

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

Tested in Regex101

Actual Result

Matched 3 last lines

11. TEST 2 : Inter Citro File
111. TEST 3 : Inter Citro File
111.TEST4 : Match this

[EDIT]

When I try the SaSkY response, it will only match lines that have digits after dots after no blank characters.

I try to delete dot after digits it will not match.

Demo

Expected Result :

111.TEST4 : Match this
111TEST4 : Match this

>Solution :

Try this:

^\d+(?:\.\S|[A-Z]).*
  • ^ start of the line.
  • \d+ one or more digits.
  • \. literal dot .
  • \S any character except a whitespace character.
  • .* zero or more characters.

See regex demo

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