[英]Finding fragment in a string (a href) with regex
I have the following snipped: 我有以下内容:
<a href="$click_tracking_url$&landing_url=someurl" border="0" alt=""></a>
What i want is just the someurl
. 我想要的只是
someurl
。 However there are variations such as following: 但是,存在以下变化:
<a href='$click_tracking_url$&landing_url=someurl' border="0" alt=""></a>
<a target=blank href="$click_tracking_url$&landing_url=someurl" alt=""></a>
I had this regex but doesnt work for variations: 我有这个正则表达式,但不适用于变体:
<a href=\".*?landing_url=(.*?)\">
how can i fix it or if there is an easier way to do it? 我该如何解决呢?还是有更简单的方法来解决呢?
You did not match all the variations because you did not consider the attributes between href
and <a
. 您没有匹配所有变体,因为您没有考虑
href
和<a
之间的属性。 Try that instead: 尝试改用:
Pattern p = Pattern.compile("<a[^>]+href=[\\\\'\\\\\\"].+&landing_url=(.+?)[\\\\'\\\\\\"]");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.