Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

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

0 votes
35 views
added Dec 6, 2020 in Regex by lcjr Second Warrant Officer (3,820 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);
  });
}); 

 

Please log in or register to response this reference.

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