This Regex is not working for below given string, as below string has “href”. I am using scala 2.11.11
val p1 = Pattern.compile("href=\"(.*?)\"")
val m1 = p1.matcher(bodyString)
while(m1.find()){
println(m1.group(1))
}
String:
"<p>Is this person trying to advertise a sound card? They dont seem to be answering my questions either </p><p><br /></p><p><a href=\"https://discussion.xyz.com/thread/2524?answerId=25022&page=1\" target=\"_blank\" rel=\"nofollow opener referrer\">https://discussion.xyz.com/thread/250274?answerId=250722&page=1</a></p>"
Please suggest if any other way to do this.
Thanks
Your expression seems to be fine, there are just two backslashes in the input string that can be likely included, maybe in this form:
href=\\\"(.*?)\\\"
or if we'd be searching for https
patterns, we could simplify it to:
\\"https?:(.*?)\\"
and our desired link is in the capturing group #1
.
If this expression wasn't desired and you wish to modify it, please visit this link at regex101.com .
jex.im visualizes regular expressions:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.