[英]Regular expression to check whether bracket [containing alphanumeric characters] exists after specific word in string
我需要正则表达式来检查字符串中是否包含包含字母数字字符的方括号[]。 方括号应放在Subject:
词之后。
sometext..Subject: Auto Reply Re: Some information, anything [0000] continue with anything
我有正则表达式为preg_match('#\\[(.*?)\\]#', $text, $match); print $match[1];
preg_match('#\\[(.*?)\\]#', $text, $match); print $match[1];
它应该返回0000
作为输出
这将找到“主题”并捕获方括号中的以下内容。
$text ="sometext [1111] ..Subject: Auto Reply Re: Some information, anything [0000] continue with anything";
preg_match('#Subject.*?\[(.*?)\]#', $text, $match);
print $match[1]; //0000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.