Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正则表达式匹配字符串中的所有*文本_Php_Javascript_Html_Regex - Fatal编程技术网

Php 正则表达式匹配字符串中的所有*文本

Php 正则表达式匹配字符串中的所有*文本,php,javascript,html,regex,Php,Javascript,Html,Regex,我需要一个正则表达式,它将匹配所有以*开头的字符串,直到它遇到它应该是这样的: 使用PHP: preg_match_all("#\*(.+?)<#", $stringWithText, $matches, PREG_SET_ORDER); $mCount = count($matches); foreach ($matches as $match) echo "Matched: " . $match[1] . "<br/>"; preg\u match\u all(

我需要一个正则表达式,它将匹配所有以*开头的字符串,直到它遇到它应该是这样的:

使用PHP:

preg_match_all("#\*(.+?)<#", $stringWithText, $matches, PREG_SET_ORDER);
$mCount = count($matches);

foreach ($matches as $match)
    echo "Matched: " . $match[1] . "<br/>";

preg\u match\u all(“\\*(.+?)它应该类似于:

使用PHP:

preg_match_all("#\*(.+?)<#", $stringWithText, $matches, PREG_SET_ORDER);
$mCount = count($matches);

foreach ($matches as $match)
    echo "Matched: " . $match[1] . "<br/>";
preg\u match\u all(“\*(.+?)试试
\*(.+?)试试
\*(.+?)试试这个:

试试这个:


我会用这样的东西


(?我会用这样的东西


(?根据你的描述,你的例子应该匹配
商店,他买了一个玩具和
,然后去他的车上买了
。这就是你的意思吗?根据你的描述,你的例子应该匹配
商店,他买了一个玩具和
然后去他的车上买了
。这就是你的意思吗?它有效,但是我如何修改以匹配,即使最后没有<,它也会继续匹配,直到找到一个“这也会在新行停止匹配吗?不…你没有要求这样做。
\*(.+?)[它可以工作,但我如何修改以匹配,即使最后没有<,它会继续匹配,直到找到一个”这也会在新行停止匹配吗?不…你没有要求这样做。
\*(.+?)[我如何使它匹配直到它找到一个“我如何使它匹配直到它找到一个”你能使新行字符也打破匹配吗?你能使新行字符也打破匹配吗?
<pre>
<?
$s = 'bob went to the *store and he bought a toy and <then he went outside *and went to his car for <a ride.';

preg_match_all("/\*([^<]+)/", $s, $matched); 
print_r($matched);
?>
Array
(
    [0] => Array
        (
            [0] => *store and he bought a toy and 
            [1] => *and went to his car for 
        )

    [1] => Array
        (
            [0] => store and he bought a toy and 
            [1] => and went to his car for 
        )

)
(?<=\*).*?(?=<|$)