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

Regex to match entire line starting with non numeric word

I’m working on certain data, and want to sort out them using regex. My requirement is that I want to match every line starting with a non numeric word. I’m tried using.

/^[^\d\s]+\b.*/gm

However the above regex doesn’t match lines like –

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

"12#22 why is it so"

Regex considers 12#22 as a numeric word but 12#22 is a non numeric word. Can anyone explain the proper solution for my case.

>Solution :

/^[^\d\s]+\b.*/gm matches any line that starts with one or more characters other than digits and whitespaces followed with a word boundary. 12#22 why is it so starts with a digit, so it is not a match.

You need

/^(?!\d+[^\S\n\r]).*/gm

Details:

  • ^ – start of a line
  • (?!\d+[^\S\n\r]) – immediately to the right of the current location, there should be no one or more digits and then a horizontal whitespace
  • .* – rest of the line.

See the 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