Created
May 7, 2018 11:21
-
-
Save nobita4176/6e57c02426dcc1db43126b68eb2dbb2b to your computer and use it in GitHub Desktop.
限界正規表現
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function to_link(str) { | |
var r_alpha = '[A-Za-z]'; | |
var r_escape = '(?:%[0-9A-Fa-f]{2})'; | |
var r_xalpha = '(?:[-0-9A-Za-z$_@.&!*"\'(),]|'+r_escape+')'; | |
var r_xpalpha = '(?:\\+|'+r_xalpha+')'; | |
var r_xealpha = '(?:=|'+r_xalpha+')'; | |
var r_hostname = '(?:'+r_alpha+r_xpalpha+')(?:\\.'+r_alpha+r_xpalpha+')*'; | |
var r_hostnumber = '(?:[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)'; | |
var r_host = '(?:'+r_hostname+'|'+r_hostnumber+')'; | |
var r_port = '(?::[0-9]+)' | |
var r_path = '(?:'+r_xpalpha+'+)(?:\\/'+r_xpalpha+'*)*'; | |
var r_search = '(?:'+r_xealpha+'+)(?:\\+(?:'+r_xealpha+'+))*' | |
var r_httpaddress = 'https?:\\/\\/'+r_host+r_port+'?'+'\\/?(?:'+r_path+')*'+'(?:\\?'+r_search+')?'+'(?:#'+r_xpalpha+'+)?'; | |
// console.log(r_httpaddress); | |
return (str+'').replace(new RegExp(r_httpaddress, 'g'), '<a href="$&" target="_blank">$&</a>'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment