繁体   English   中英

正则表达式采用字符串PHP的一部分

[英]Regular Expression take a part of a string PHP

例如,我有以下字符串

$s = "asd$5asd";

我怎样才能只使用包含“$ 5”的部分来自php中的“d”后我们有以下内容

preg_mach //returns int number of matches
preg_replace //returns the string with a replaced content
//---------------------
preg_grep    //it greps but how to grep the "$5" 
             //that comes after "d" without grepping the "d" it's self ???

我的正则表达式是

/((coupon|enter)\x20code\x20)("([^"]+)")/

我想grep四个括号的价值(4美元)

取决于你想要匹配的内容,但以下将返回所有匹配 -

preg_match_all('/d(\$[0-9]+)/i',$s,$aMatches);

$aMatches[1]包含所有匹配的数组。 示例匹配 - $ 5 $ 10 $ 20(仅匹配$和任意长度的数字)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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