如何用PHP 正则匹配

如何用PHP 正则匹配出含有HTML标签的字符串中的英文单词

<div class="set_en"><div><span style="font-weight: bold;">Chapter 2</span></div>It was seven o'clock on Saturday evening.Jackie stood at the window. A car drove slowly up to the front door and stopped. A tall man with white hair got out. It was Albert, the husband of Molly's sister.</div><div class="set_cn"><div><span style="font-weight: bold;">章节2</span></div>星期六晚上 7 点。杰基站在窗前。一辆小车徐徐驶到前门停下来。一个白头发、高个子的男人下了车他是艾伯特,莫利姐姐的丈夫。</div><div class="set_en">'Here's Uncle Albert,' Jackie said. 'Always late.'She went out of the room and opened the front door. Albert came in and went at once to Molly.</div><div class="set_cn">“是艾伯特姨父,”杰基说。“他总是迟到。”她走出房间打开前门。艾伯特走进来,立刻便走向莫利。</div><div class="set_en">'Oh, dear. I'm very late. I am sorry,' Albert said.'Fifty years old today! What a wonderful dress!'Molly did not smile. 'Thank you, Albert. We're all getting older.' Tonight she wore a long black dress, and the two black dogs sat at her feet.'Everyone is here now. Let's go in to dinner,' she said.</div><div class="set_cn">“哦,亲爱的,抱歉,我来得太迟了,”艾伯特说。“今天是你 50 岁生日!多漂亮的裙子!”莫利没有笑。“谢谢你,艾伯特。我们都老了。”今晚她穿了一条长长的黑裙子,两条黑狗蹲在她脚边。“现在大家都到了,咱们吃饭吧。”她说</div><div class="set_en">Everyone stood up and went to the table.'The table looks nice, Jackie. What wonderful flowers!' Diane said. She was a beautiful girl, with long black hair and dark blue eyes. She wore a long red dress.</div>

如何把上面字符串中的,正文中的,英文单词都匹配出来,
也就是不要标签中的英文,把类似div span p 这样的标签中的英语除外,谢谢指教


一只萌萌小番薯
浏览 556回答 2
2回答

largeQ

通过仔细阅读问题描述,样本采用 html&nbsp;格式编写,其内容为中英文互译,如问题所要求的:“正文中的,英文单词都匹配出来”。

Smart猫小萌

提供一下思路:建议可以将问题简化一下,即只取正文中的英文部分。通过观察如上提供的样本中,大部分的英文部分都以标签&nbsp;<div class="set_en">...</div>(其中有一个 div&nbsp;标签没有配对) ,则步骤如下:1、先编写正则取出标签中的内容:2、再对每个英文句子,取出其中的单词:
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5