查找两个字符之间的文本


Find the text between two Characters

我想找到两个字符之间的文本

$var ='J111 king Jadv oops J123 php';

在上面的变量中,我只得到字母从J.开始

我需要以下输出,

起始J值为

Array ( [0] =>J111 [1] => Jadv [2] => J123) 

和余额值为,

Array ( [0] =>king [1] => oops [2] => php)

您可以尝试使用:

$var ='J111 king Jadv oops J123 php';
//get all the words in array
$words = preg_split('/'s+/', $var);
//match all the words starting with letter J
preg_match_all('(J[^'s]+)', $var, $matches);
//words with matching letter
$words_with_letter = $matches[0];
//words without matching letter
$words_without_letter = array_values(array_diff($words,$words_with_letter)); 

希望这对您有所帮助:)

Regex获取所有J值(实时演示:http://regexr.com?306v4)

/(J[^'s]+)/g

目前正在研究另一个。