What is a regex to match ONLY an empty string?

What is a regex to match ONLY an empty string?

回答1

I would use a negative lookahead for any character:

^(?![sS])

This can only match if the input is totally empty, because the character class will match any character, including any of the various newline characters.

回答2

Wow, ya'll are overthinking it. It's as simple as the following. Besides, many of those answers aren't understood by the RE2 dialect used by C and golang.

^$


在js中进行测试
/^$|^[0-9]{7,11}$/.test("")
原文地址:https://www.cnblogs.com/chucklu/p/14261985.html