Regular expressions that match Chinese characters: [U4E00-U9FA5]
Match double-byte characters (including kanji): [^x00-xff]
Application: Calculates the length of a string (a double-byte character length meter 2,ascii character 1)
String.prototype.len=function () {return This.replace ([^x00-xff]/g, "AA"). Length;
Regular expression that matches a blank line: [s|] *
Regular expression matching HTML tags:/< (. *) >.*|< (. *)/>/
Regular expression matching the leading and trailing spaces: (^s*) | (s*$)
Application: There is no trim function like VBScript in JavaScript, and we can use this expression to do the following:
String.prototype.trim = function () {
Return This.replace (/(^s*) | ( s*$)/g, "");
}
Use regular expressions to decompose and convert IP addresses:
The following is a JavaScript program that matches an IP address with a regular expression and translates an IP address into a corresponding value:
function IP2V (IP) {
re=/(d). (d). (d). (d)/g//matched regular expression of IP address
if (Re.test (IP)) {
Return Regexp.*math.pow (255,3)) Regexp.*math.pow (255,2)) regexp.*255 regexp.*1
}
else {
throw new Error ("not a valid IP address!")
}
}
However, the above program without regular expression, and directly with the split function decomposition may be more simple, the program is as follows:
var ip= "10.100.20.168"
Ip=ip.split (".")
Alert ("IP value is:" (ip[0]*255*255*255 ip[1]*255*255 ip[2]*255 ip[3]*1))
Regular expression that matches the email address: w ([-.] W) *@w ([-.] W) *.W ([-.] W) *
Regular expression matching URL URL:/http ([W].) [W] (/[w-./?%&=]*)?
An algorithmic program that uses regular expressions to remove repeated characters from a string:
var s= "Abacabefgeeii"
var s1=s.replace (/(.). */g, "")
var re=new RegExp ("[" S1 "]", "G")
var s2=s.replace (Re, "")
Alert (S1 s2)//Result: ABCEFGI
A JavaScript program that extracts file names from URL addresses with regular expressions, with the following result as Page1
S= "Http://www.9499.net/page1.htm"
S=s.replace (/(. */) ([^.]). */ig, "")
Alert (s)
Use regular expressions to restrict the entry of text boxes in Web Forms:
http://www.bkjia.com/PHPjc/445169.html www.bkjia.com true http://www.bkjia.com/PHPjc/445169.html techarticle regular expression matching Chinese characters: [U4e00-u9fa5] matches double-byte characters (including kanji): [^x00-xff] Apply: Calculates the length of a string (a double-byte character length meter 2,a ...