正则表达式提取标记之间的文本,但不提取标记之间的文本 [英] Regex that extracts text between tags, but not the tags
本文介绍了正则表达式提取标记之间的文本,但不提取标记之间的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个正则表达式来提取字符串中两个标签<title>
之间的内容,而不是标签中的内容.
IE,我有以下
I want to write a regex which extract the content that is between two tags <title>
in a string but not the tags.
IE I have the following
<title>My work</title>
<p>This is my work.</p> <p>Learning regex.</p>
正则表达式
(<title>)(.*?)(<\/title>)
提取<title>My work</title>
,但我只想提取My work
.我怎样才能做到这一点?
这是到示例 http://regex101.com/r/mD8fB0
extracts <title>My work</title>
but I want to extract only My work
. How can I do that?
This is a link to the example http://regex101.com/r/mD8fB0
推荐答案
您可以使用以下正则表达式:
You can use this following Regex:
>([^<]*)<
或> [^<] *<
or, >[^<]*<
然后消除不需要的字符,例如<" & '>'
Then eliminate unwanted characters like '<' & '>'
这篇关于正则表达式提取标记之间的文本,但不提取标记之间的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文