Matching an empty string with regex

前端 未结 5 865
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 20:21

I\'ve seen posts here on stackoverflow that say that the regex ^$ will match an empty string... So it made me think... why not something like this: ^\\s+$

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-20 20:53

    ^\s+$ will match a sequence of one or more whitespaces, which is not an empty string at all.

    An empty string does not contain any character, not even whitespace. However, if you use ^\s*$, it will match an empty string in addition to whitespaces.

提交回复
热议问题