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?

closed as off-topic by glls, Martin Lezer, Oleksandr Berehovskyi, Gortonington, Markus Slabina Sep 18 '17 at 12:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions not specific to Salesforce are off-topic here, but can be asked on Stack Overflow." – glls, Martin Lezer, Oleksandr Berehovskyi, Gortonington, Markus Slabina
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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

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

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