There are lots of posts about regexs to match a potentially empty string, but I couldn't readily find any which provided a regex which only matched an empty string.
I know that ^
will match the beginning of any line and $
will match the end of any line as well as the end of the string. As such, /^$/
matches far more than the empty string such as "
", "foobar
", etc.
I would have thought, though, that /A/
would match just the empty string, since A
matches the beginning of the string and
matches the end of the string. However, my testing shows that /A/
will also match "
". Why is that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…