问题描述
我正在使用下面的正则表达式在给定的字符串中查找 title
标记的内容:
alert(< title> kjkj</title>< title> jjjjj</title>".match(/< title [^>] *>([[^<]+)< \/title>/)[1]);
接下来,我想找到 meta property ="og:title"
的 content
:
<元属性="og:title" content ="The Rock"/>
是字符串
我不知道该怎么做.我无法使用jQuery或创建任何DOM元素.它是纯字符串,我只需要处理给定的字符串
好,没有DOM,这是正则表达式:
/content \ = \([[A-Za-z0-9 _] *)\"/
如果由于某些原因,您不想匹配字符串中的其他内容属性,则可以更加具体:
/meta \ sproperty \ = \"og \:title \" \ scontent \ = \([[A-Za-z0-9 _] *)\"/
这是一个非常有用的网站,可以轻松测试不同类型的正则表达式./p>
I am using below regex to find the content of title
tag in a given string:
alert("<title >kjkj</title><title>jjjjj</title>".match(/<title[^>]*>([^<]+)<\/title>/)[1]);
Next I want to find the content
of meta property="og:title"
:
<meta property="og:title" content="The Rock" />
is a string
I have no clue how to do that. I can't use jQuery or create any DOM element. Its pure a string and i have to work on a given string only
Ok, no DOM, here is the regex:
/content\=\"([A-Za-z0-9 _]*)\"/
And if for some reason there are other content attributes in the string that you don't want to match you can just be more specific:
/meta\sproperty\=\"og\:title\"\scontent\=\"([A-Za-z0-9 _]*)\"/
This is a very helpful site where it is easy to test regexes of different types.
这篇关于javascript正则表达式以获取标签属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!