具有所有属性的锚标记的正则表达式 [英] Regular expression for anchor tag with all attributes

查看:43
本文介绍了具有所有属性的锚标记的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取一个正则表达式,以替换文本字符串中的所有链接作为链接的值.

I'm trying to get a regular expression to replace all the links out of a text string for the value of the link.

链接可能看起来像这样:

A link may look like these:

<a href="http://whatever" id="an_id" rel="a_rel">the link</a>
<a href="/absolute_url/whatever" id="an_id" rel="a_rel">the link</a>

我想要一个得到的正则表达式:链接

I want a regular expression that I get: the link

推荐答案

/<a[^>]*>([^<]+)<\/a>/g

这远非完美,但您需要提供更多示例,说明什么是正确的匹配项,什么不是正确的匹配项(例如空白)?

It's far from being perfect, but you need to provide more examples of what is a correct match and what isn't (e.g. what about whitespaces?)

这篇关于具有所有属性的锚标记的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆