[英]Regular expression php after a string
Hi I have a very long text standard and I want to take a part of a string after a standard string: 嗨,我有一个很长的文本标准,我想在一个标准字符串之后加入一个字符串的一部分:
$string = "bla bla bla... Refer: my text /n bla bla bla";
I want to take the string: my text
. 我要输入字符串:
my text
。 Is ever after Refer:
and before a /n
or /r
. 始终在
Refer:
之后Refer:
/n
或/r
。 Is possible with a regular expression? 正则表达式可能吗? I have done this wit substr and strpos but I want to optimize my text.
我已经完成了这个问题,但是我想优化我的文本。
\\ s表示空格^表示除
preg_match('|.*Refer:\s+([^/n/r]*)|', $string, $out);
preg_match('/Refer:\s+(.*?)$/i', $string, $matches);
echo $matches[0];
$regex = "/.*Refer:(.*?)(?:\/n|\/r)/";
preg_match($regex, $string, $matches);
echo $matches[1];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.