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 –

"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.

Leave a Reply