regex - JavaScript Encoding? -
i'm having little trouble javascript file not loading correctly on different computers. have line in javascript file:
var url_regexp = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi;
it loads fine on computer, on friends computer chinese operating system language, browser shows javascript error. on debugging code, found line has been served this:
var url_regexp = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?芦禄鈥溾€濃€樷€橾))/gi;
note random characters @ end of line.
i'm guessing encoding problem... ideas on how solve this? should encoding javascript files in utf8 or something? if so, how? save file encoding or there javascript tag can use? using html meta content-type tag serves character-encoding utf-8.
any appreciated.
see unicode in regex :
to match specific unicode code point, use \uffff ffff hexadecimal number of code point want match.
so should replace «»“”‘’
\u00ab\u00bb\u201c\u201d\u2018\u2019
characters' code see utf-8 character table.
Comments
Post a Comment