简体   繁体   中英

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 . Is ever after Refer: and before a /n or /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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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