简体   繁体   English

检查字符串中特定单词后是否存在括号[包含字母数字字符]的正则表达式

[英]Regular expression to check whether bracket [containing alphanumeric characters] exists after specific word in string

I need regular expression to check whether square bracket [] containing alphpnumeric characters exists in string. 我需要正则表达式来检查字符串中是否包含包含字母数字字符的方括号[]。 Bracket should be after Subject: word. 方括号应放在Subject:词之后。

sometext..Subject: Auto Reply Re: Some information, anything [0000] continue with anything

I have regular expression as preg_match('#\\[(.*?)\\]#', $text, $match); print $match[1]; 我有正则表达式为preg_match('#\\[(.*?)\\]#', $text, $match); print $match[1]; preg_match('#\\[(.*?)\\]#', $text, $match); print $match[1];

It should return 0000 as output 它应该返回0000作为输出

This will find "subject" and capture the following contents of a square bracket. 这将找到“主题”并捕获方括号中的以下内容。

$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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM