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

Match whitespace except a specific line that itself contain a whitespace

I have this example:

ED Ess  Nb  Ip

I would like to capture all whitespaces except the two present between "Ess" and "Nb".

ED·Ess  Nb··Ip

Where · indicate what should be captured.

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

I have try:

(?<!Ess\s)\s+

But it does not work since the Negative Lookbehind itself contains what should be captured.

Do you have a solution ?

>Solution :

Seems like you have to use both negative lookbehind and lookahead to check if Ess or Nb is nearby.

/(?<!Ess)\s(?!Nb)/gm

Here is test

P.S. I might notice that there is an edge case where the regexp would capture whitespaces if there are more than two present between Ess and Nb.

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