其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

正则表达式中,如何获取括号中的网址,不包含括号和单引号

GG网络技术分享 2025-03-18 16:14 2


问题描述:

我想用正则表达式匹配括号中的网址,不包含括号和单引号

比如:

<a onclick=\"window.open(\'https://www.xxxxx.com/i6xcddc\');return false;\" class=\"sbtn _sd_Highlight_Select\" title=\"\" sdhref=\"#down\" style=\"cursor: default;\"><i class=\"ico\"></i><i class=\"line\">

我想要获得 括号中的 https://www.xxxxx.com/i6xcddc,不包括单引号。

请问该如何 用正则表达式 来写?

网友观点:

(?<=window\\.open\\(\\\').*?(?=\\\'\\))

注意,这个正则适合Java,js不支持零宽断言,得先匹配完整,再去掉多余的字符。

如果不硬性要求使用正则表达式,可以使用下面的代码块:

        String s=\\\"window.open(\'https://www.xxxxx.com/i6xcddc\');return false;\\\";

int from=s.indexOf(\'(\')+2;

int to=s.indexOf(\')\')-1;

String str=s.substring(from, to);

爬虫笔记——正则表达式

正则表达式(Regular Expression)的作用是在获取网上信息后,对其中有用并且有规律的信息进行提取。python中自带了一个正则表达式模块"re",使用前需要先导入这个模块。导入语句:

标签:

提交需求或反馈

Demand feedback