The below regex will match only the characters which are just after to the string regex
,
/(?<=regex\s)(.*)/s
DEMO
Your PHP code would be,
<?php
$mystring = "some text for test and need to replace by regex using php.
We have another sentence";
$regex = '~(?s)(?<=regex\s)(.*)~';
if (preg_match($regex, $mystring, $m)) {
$yourmatch = $m[0];
echo $yourmatch;
}
?>
Output:
using php.
We have another sentence
Explanation:
(?s) # Allows . to match anything(including newlines)
(?<=regex\s)(.*) # Positive lookbehind is used. It matches anything after the string regex followed by a space.