Php 正则表达式匹配字符串中的所有*文本
我需要一个正则表达式,它将匹配所有以*开头的字符串,直到它遇到它应该是这样的: 使用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(
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
)
)
(?<=\*).*?(?=<|$)