inevitably, the regular expression will search for at least one character. I came across a case where an empty line did not pass this test already, it would be better to use it .*?or (.*)?instead, sometimes you need to specify a part of the line, which can be zero in curly brackets before the question mark, this helps. For example. \d{6}?will lead to an incorrect result, whereas if I said (\d{6})?in a line, say, for example:
preg_match("/shu\.(\d{6})?/", "shu.321456")
this will give true, and so will be a string "shu."without any int after period
source
share