Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这样的模式'D34566'。我如何检查给定字符串中包含的此模式。
String = D34566-Test Case. Pattern = D followed by 5 digits.
即以 D 开头后跟 5 位数字的单词。
您可以尝试以下模式来检查您要在字符串中的任何位置找到的单词:
if (preg_match('/\bD\d{5}\b/', $string)) { // OK }
preg_match("/^D\d{5}/", $string)
像这样:
preg_match('/^(D\d{5})/', String);