Regex fixed - certain symbol is not included into regex (hyphen or accents)

0 votes
360 views
added Dec 6, 2020 in Regex by lcjr First Warrant Officer (11,850 points)
edited Dec 6, 2020 by lcjr
$(document).ready(function() {
  $('.qa-extra').each(function(){ 
      var str = $(this).html(); 
      // instead of this
      var regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/ig
      
      // use this, in this, regex adding - and % into logic 1) \-\% 2) \-%
      var regex = var regex = /(https?:\/\/([-\w\-\%\.]+)+(:\d+)?(\/([\w\-%\/_\.]*(\?\S+)?)?)?)/ig
      // Replace plain text links by hyperlinks
      var replaced_text = str.replace(regex, "<a href='$1' target='_blank'>$1</a>");
      // Echo link
      $(this).html(replaced_text);
  });
}); 

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...