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

I don't want match abc with spaces AT ALL if followed by some other non space characters

I use this regex https://regex101.com/r/7Cw1fy/1

abc(\s*)(?![\S]+)

abc matches -> OK

abc cde matches -> not OK

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

>Solution :

You can use

abc(?!\s*\S)(\s*)

See the regex demo. Details:

  • abc – a fixed string
  • (?!\s*\S) – a negative lookahead that fails the match if there are zero or more whitespaces followed with a whitespace immediately to the right of the current location
  • (\s*) – Group 1: zero or more whitespaces.
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