mercredi 24 décembre 2014

whitespace before or after characters, symbols, or numbers; but, not in-between


I'm trying to write a regexp that selects whitespace before or after any character( letters, symbols, or numbers ), but not in-between words composed of the characters.


For example, in abc, the spaces before would match; but, in words words words none of the whitespace in-between would be selected.


So in hello world to everyone, only the leading and trailing whitespace would be selected.


Bonus: if there's a way to separately, in a second regexp, select the white-space in-between, that would help alot.


What i'm trying to do is, in javascript, minimise the whitespace in a sentence so that leading and trailing whitespace is gone and the white-space in-between words is shrunk to 1 space.





Aucun commentaire:

Enregistrer un commentaire