Preg Match Empty String

前端 未结 5 1947
不知归路
不知归路 2020-12-30 20:19

How to preg_match for an null (empty) string??

I need something like:

/([0-9]|[NULL STRING])/
5条回答
  •  春和景丽
    2020-12-30 20:34

    You can use ^ to match beginning-of-line, and $ to match end-of-line, thus the regular expression ^$ would match an empty line/string.

    Your specific example (a line/string containing a single digit or being empty) would easiest be achieved with ^[0-9]?$.

提交回复
热议问题