gpt4 book ai didi

php - 正则表达式匹配字符串中的所有 *texttexttext

转载 作者:行者123 更新时间:2023-11-30 09:04:27 26 4
gpt4 key购买 nike

我需要一个正则表达式来匹配所有以 * 开头的字符串,直到它遇到 <

因此在这段文本中:bob went to the *store and he bought a toy and <then he went outside *and went to his car for <a ride.

它会匹配 bob went to the *store and he bought a toy andand went to his car for

如果没有“<”它将匹配所有直到行尾

最佳答案

试试这个:

<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
)

)

关于php - 正则表达式匹配字符串中的所有 *texttexttext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6362178/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com