Below is the regex I tried to get all the urls from string:
(?:(?:(?:[a-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[a-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[a-z0-9.-]+)((?:\/[+~%\/.\w-]*)?\??(?:[-+=&;%@.\w]*)#?\w*)?)
It is working fine here, check this out http://regexr.com/3cgrq
but if I use pattern matching in salesforce get multiple error.
Illegal character sequence '/' in string literal.
If I remove all the \
then I get another error
System.StringException: Invalid regex: Dangling meta character '?'
Pls try to execute below code in developer console
String myvar = 'raewaferwww.dilyan.co.ukhrewadfea'+
''+
'<span style="color: #5f604b;">'+
'<span style="font: signacondcolumn-book;">'+
'<span style="font-size: 8.0pt;">https://www.merchant.com/store</span>'+
'</span>'+
'</span>'+
'<br>'+
'<a href\'="www.account.com">Account</a>';
// First, instantiate a new Pattern object "MyPattern"
Pattern MyPattern = Pattern.compile('(?:(?:(?:[a-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[a-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[a-z0-9.-]+)((?:\/[+~%\/.\w-]*)?\??(?:[-+=&;%@.\w]*)#?\w*)?)');
// Then instantiate a new Matcher object "MyMatcher"
Matcher MyMatcher = MyPattern.matcher(myvar);
while (MyMatcher.find()) {
System.debug(MyMatcher.group());
}
Illegal character sequence '\/' in string literal.
If I remove all the `\` then I get another error like reg exp not valid