How to preg_match for an null (empty) string??
I need something like:
/([0-9]|[NULL STRING])/
The preg_match() function returns whether a match was found in a string.
preg_match is case sensitive. A match. Add the letter "i" to the end of the pattern string to perform a case-insensitive match.
preg_match() in PHP – this function is used to perform pattern matching in PHP on a string. It returns true if a match is found and false if a match is not found. preg_split() in PHP – this function is used to perform a pattern match on a string and then split the results into a numeric array.
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]?$
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With