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

Regular Expression to remove every whitespace which is not after a comma

i want to replace remove/replace every whitespace in a string which is not after a comma.
I already searched for a suitable regex but i did not find one.
Here is a sample of the strings i want to modify:

{id=565189.0, server=Ealyn, merchantName=Nox, activeMerchants=[{id=f01b617d-2dc7-4597-2297-08dabad9a125, name=Nox, zone=Nebel horn, card={name=Bergstrom, rarity=2.0}, rapport={name=Energy X7 Capsule, rarity=3.0}, votes=0.0}]}

should change to (_ trough replace)

{id=565189.0, server=Ealyn, merchantName=Nox, activeMerchants=[{id=f01b617d-2dc7-4597-2297-08dabad9a125, name=Nox, zone=Nebel_horn, card={name=Bergstrom, rarity=2.0}, rapport={name=Energy_X7_Capsule, rarity=3.0}, votes=0.0}]}

Can someone with a high knowledge then me over regular expression’s create one for this case?
Thanks in advance

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 already tried this expression:

(^|[^,])\\s+

.. but it always removed a character with the whitespace

>Solution :

This can be accomplished using a negative lookbehind:

(?<!,)\\s+

The Output:

{id=565189.0, server=Ealyn, merchantName=Nox, activeMerchants=[{id=f01b617d-2dc7-4597-2297-08dabad9a125, name=Nox, zone=Nebel_horn, card={name=Bergstrom, rarity=2.0}, rapport={name=Energy_X7_Capsule, rarity=3.0}, votes=0.0}]}
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