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