0

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.

2
  • 1
    substr and strpos along with their multibyte counterparts are more efficient than regular expressions. Commented Jan 18, 2013 at 9:08
  • Yes but I want to try with a pattern if is possible Commented Jan 18, 2013 at 9:10

3 Answers 3

1

\s signifies blank space ^ signifies except

preg_match('|.*Refer:\s+([^/n/r]*)|', $string, $out);
Sign up to request clarification or add additional context in comments.

Comments

0
preg_match('/Refer:\s+(.*?)$/i', $string, $matches);
echo $matches[0];

Comments

0
$regex = "/.*Refer:(.*?)(?:\/n|\/r)/";
preg_match($regex, $string, $matches);
echo $matches[1];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.