how can I exctract attribute value using JAVA regex -


i have such string:

<a href="https://host-test.com/create?username=test3&amp;user-mail=myemail@gmail.com&amp;id=14b72820-3855-4f2b-9a39-543ced6784a0&amp;downloadurl=https://host-test.com:443/123/rest/tmp-z7vvymo3wmfzke/vfs/v2/downloadzip/&amp;projectid=d29ya3nwywnlexfpyxlwzjgwb2sxnda2mjovy3jlyxrlqwnj:createacc;" style="font-family:myriad pro,arial,tahoma,serif;color:#fff;font-size:14px;text-decoration:none;font-weight:bold" title="confirm tenant creation" target="_blank">                             <div style="font-family:'lucida grande',sans-serif;border-radius:5px;width:120px;min-height:40px;line-height:40px;border:1px solid #577e15;color:#fff;text-align:center;background:#e77431;margin:15px 0 15px">                                 confirm                             </div>                         </a> 

and need extract using regexp href value:

https://host-test.com/create?username=test3&amp;user-mail=myemail@gmail.com&amp;id=14b72820-3855-4f2b-9a39-543ced6784a0&amp;downloadurl=https://host-test.com:443/123/rest/tmp-z7vvymo3wmfzke/vfs/v2/downloadzip/&amp;projectid=d29ya3nwywnlexfpyxlwzjgwb2sxnda2mjovy3jlyxrlqwnj:createacc; 

also href value each time can different shorter or longer

mystring.replacefirst(mystring, "^<a\\s+href\\s*=\\s*\"([^\"]+)\".*", , "$1"); 

assuming mystring contains string a element.

as href attributes cannot nested, should fine , no full html parser needed. restriction find href attributes in double quotes.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -