我有一个字符串,例如以下内容:
Are you looking for a quality real estate company?
<s>Josh's real estate firm specializes in helping people find homes from
[city][State].</s>
<s>Josh's real estate company is a boutique real estate firm serving clients
locally.</s>
In [city][state] I am sure you know how difficult it is
to find a great home, but we work closely with you to give you exactly
what you need
我希望将这一段根据 <s> </s>
标签拆分成一个数组,以便得到以下数组作为结果:
[0] Are you looking for a quality real estate company?
[1] Josh's real estate firm
specializes in helping people find homes from [city][State].
[2] Josh's real estate company is a boutique real estate firm serving clients
locally.
[3] In [city][state] I am sure you know how difficult it is
to find a great home, but we work closely with you to give you exactly
what you need
这是我目前正在使用的正则表达式:
$matches = array();
preg_match_all(":<s>(.*?)</s>:is", $string, $matches);
$result = $matches[1];
print_r($result);
但是这个函数只会返回在<s> </s>
标签之间的文本数组,它会忽略这些标签之前和之后的文本。(在上面的例子中,它只会返回数组元素1和2。)
有什么想法吗?
</s>
,这意味着像my name is bob. im 17 </s>.
和my name is bob. <s>im 17</s>
这样的句子都会被分成两个元素,能否更改使得第一个例子仅保留一个数组元素?(我希望未匹配的未关闭的</s>
不会被匹配)。 - Ali