PHP preg_match needed to ensure only ONE space character is allowed between words

后端 未结 3 1754
广开言路
广开言路 2020-12-11 23:47

basically I need a preg_match that ensures that only one space character is allowed between each word (IF there is more than one word).

My existing rule is:

3条回答
  •  一向
    一向 (楼主)
    2020-12-12 00:18

    /^[\S]+\s?[^\s]?/i
    

    Will search for any word with one space after it and not a space after that one space

    /\s?\S+\s/
    

    Will search for any character with whitespace on either side or only on the end.

提交回复
热议问题