I have such string:
<a href="https://host-test.com/create?userName=test3&user-mail=myemail@gmail.com&id=14b72820-3855-4f2b-9a39-543ced6784a0&downloadurl=https://host-test.com:443/123/rest/tmp-z7vvymo3wmfzke/vfs/v2/downloadzip/&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 I need extract using regexp only href value:
https://host-test.com/create?userName=test3&user-mail=myemail@gmail.com&id=14b72820-3855-4f2b-9a39-543ced6784a0&downloadurl=https://host-test.com:443/123/rest/tmp-z7vvymo3wmfzke/vfs/v2/downloadzip/&projectid=d29ya3NwYWNleXFpYXlwZjgwb2sxNDA2MjovY3JlYXRlQWNj:createAcc;
also href value each time can be different shorter or longer
For this particular string you can try something like
but if your string can change (like href atrubute can have other atributes before it) it can not work as expected. That is one of the reasons to use parsers rather then regex.
assuming myString contains your string with the
a
element.As the href attributes cannot be nested, this should be fine and no full HTML parser is needed. A restriction is that it will only find href attributes in double quotes.