Several regular formats: Take a regular judge with judgment and judgment,
Function search_sub ()
{
Var str = document.search_form.keyword.value;
IF (Str.Replace (/ (^ / s *) | (/ s * $) / g, "") == "")
{
WINDOW.Alert ("Please enter the keyword!");
Document.search_form.keyword.focus ();
Return;
}
Document.search_form.submit ();
}
script>
Here, a document will be added to illustrate several common regular regular (unsuccessful):
Regular expressions matching Chinese characters: [/ U4E00- / u9fa5] Match Dual-byte characters (including Chinese characters): [^ / X00- / XFF] Application: Calculate the length of the string (a double-byte character lengthometer 2, ASCII characters 1) String.Prototype.len = function () {Return this.Replace ([^ / X00- / XFF] / g, "aa"). Length;} Matching a regular expression: / N [/ s |] * / R Match the regular expression of the HTML tag: / <(*)>. * // 1> | <(*) //> / match the regular expression of the first tail space: (^ / s *) | (/ s * $) application: There is no TRIM function like VBScript in JavaScript, we can use this expression to be implemented, as follows: string.Prototype.trim = function () {Return this. Replace (/ (^ / s *) | (/ s * $) / g, "");} Using Regular Expression Decomposition and Convert IP Address: The following is to match the IP address using regular expressions, and convert the IP address into Corresponding value JavaScript program: Function IP2V (IP) {RE = / (/ d ) /. (/ D ) /. (/ D ) /. (/ D ) / g // matches the regular expression IF of the IP address ( Re.Test (IP)) {RETURN Regexp. $ 1 * Math.Pow (255, 3)) Regexp. $ 2 * Math.Pow (255, 2)) Regexp. $ 3 * 255 Regexp. $ 4 * 1} Else {Throw new error ("Not a Valid IP Address!")}} However, if the above programs do not need a regular expression, it may be more simple to use the SPLIT function to decompose, the procedure 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)) Match the regular expression of the Email address: / w ([- .] / W ) * @ / w ([-.] / W ) * /. / W ([-.] / W ) * matching URL URL regular expression: http: // ([/ w-] /.) [/ W-] (/ [/ w- ./?%&=]*)? Using regular expressions to remove strings Algorithm for repeated characters: var s = "abacabefgeeii" var s1 = s.replace /(.).). "$ 11" Var Re = New Regexp ("[" S1 "]", "G") VAR S2 = S.Replace (re, "") ALERT (S1 S2) / / The result is: Abcefgi I originally posted a way to find an expression on 9CBS to implement the method of removing the repeating character, and finally did not find it, this is the simplest implementation method I can think of. The idea is to use the retrieval to remove the repeated characters, and then establish a second expression with a duplicate character, take the non-repetitive character, and the two are connected. This method may not apply for a string that requires the character sequence.