预匹配空字符串 [英] Preg Match Empty String
本文介绍了预匹配空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何为空(空)字符串 preg_match??
How to preg_match for an null (empty) string??
我需要类似的东西:
/([0-9]|[NULL STRING])/
推荐答案
您可以使用 ^
匹配行首,使用 $
匹配行尾-line,因此正则表达式 ^$
将匹配空行/字符串.
You can use ^
to match beginning-of-line, and $
to match end-of-line, thus the regular expression ^$
would match an empty line/string.
使用 ^[0-9]?$
最容易实现您的具体示例(包含单个数字或为空的行/字符串).
Your specific example (a line/string containing a single digit or being empty) would easiest be achieved with ^[0-9]?$
.
这篇关于预匹配空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文