[英]Extracting <a> from Text in javascript
I have an array which is getting text from a website using JSON parsing. 我有一个数组,它使用JSON解析从网站获取文本。
That text have an <a>
tag sometimes at the end of text and sometime in between the text. 该文本有时在文本末尾且在文本之间的某个时间带有<a>
标记。
I want to extract that <a>
tag. 我想提取该<a>
标签。
you could use regex, like: 您可以使用正则表达式,例如:
var str = "test sdf <a href='www.google.com'>test</a> sdfsdf";
var anchor = str.match(/<a[^>]*>([^<]+)<\/a>/);
console.log( anchor[0] ); //returns <a href='www.google.com'>test</a>
I'm not sure exactly what you're trying to extract, but a regular expression might be what you're looking for: 我不确定您要提取的内容是什么,但是正则表达式可能是您要寻找的内容:
/\<a.*?\>/.exec('Hello <a href="foo.html">World</a>!')
Output: 输出:
["<a href="foo.html">"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.