0

I'm using the following regular expression: (https?://(?i)www.|https?|www.)([A-Za-z\\d._~:/?#\\[\\]@!$&\'()*+,;=-]|%[0-9a-fA-F]{2})+[.][A-Za-z]{2,3}

but for urls such as for instance: http://www.url1.com<br>http://www.url2.com

the regular expression is not working.

What is the regular expression to help me escape and ignore the <br> between the urls?

  • 1
    Just spilt Urls based on "<br>" and then check for url. – NITHESH K Sep 18 '17 at 12:17
  • I've tried with .split('<br>') but it is not working. – sfdev Sep 18 '17 at 12:50
  • Try to execute below answer in anonymous window. – NITHESH K Sep 18 '17 at 12:54
1

Here is example using String.spilt() function.

String url3='http://www.url1.com<br>http://www.url2.com<br>abcd://asdasd.tt<br>http://google.com<br>http://11asds.co.in<br>https:///google.com<br>http://_fsds.co<br>https://google<br>http://google.';

String urlRegex = '^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$';
    Pattern MyPattern = Pattern.compile(urlRegex);
String[] str = url3.split('<br>');
for(String s:str) {    
    Matcher MyMatcher = MyPattern.matcher(s);
    system.debug('#####valid url :'+ MyMatcher.matches() );    
}

enter image description here

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.