javascript regular expression [Z]

2010-10-16  来源:本站原创  分类:Web  人气:406 

JS regular expressions

/ / Check whether all the numbers

function isDigit (s)
{
var patrn = / ^ [0-9] {1,20} $ /;
if (! patrn.exec (s)) return false
return true
}

/ / Check login name: Enter only 5-20 with a letter, can be a string with digital ,"_","."

1. function isRegisterUserName(s)
   2. {
   3. var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
   4. if (!patrn.exec(s)) return false
   5. return true
   6. }
# function isTrueName(s)
# {
# var patrn=/^[a-zA-Z]{1,30}$/;
# if (!patrn.exec(s)) return false
# return true
# }
# }}
#
# //  Check password  :  6-20 letters can only enter  .  Figures. Underscore
# <pre name="code">function isPasswd(s)
# {
# var patrn=/^(\w){6,20}$/;
# if (!patrn.exec(s)) return false
# return true
# }
# </pre>
# <br>
# <br>//  Check ordinary telephone. Fax Number  :  Can "+" at the beginning  ,  In addition to numbers, may contain  "-"
# <br><pre name="code">function isTel(s)
# {
# //var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/;
# var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
# if (!patrn.exec(s)) return false
# return true
# }
# </pre>
# <br>
# <br>//  Check phone number  :  Must begin with a number, in addition to numbers  ,  May contain  "-"
# <br><pre name="code">function isMobil(s)
# {
# var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
# if (!patrn.exec(s)) return false
# return true
# }
# </pre>
# <br>
# <br>//  Check Postal Code
# <br><pre name="code">function isPostalCode(s)
# {
# //var patrn=/^[a-zA-Z0-9]{3,12}$/;
# var patrn=/^[a-zA-Z0-9 ]{3,12}$/;
# if (!patrn.exec(s)) return false
# return true
# }
# </pre>
# <br>
# <br>//  Check the search keyword
# <br><pre name="code">function isSearch(s)
# {
# var patrn=/^[^`[email protected]#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`[email protected]$%^&()+=|\\\]
#         [\]\{\}:;'\,.<>?]{0,19}$/;
# if (!patrn.exec(s)) return false
# return true
# }
#
# function isIP(s) //by zergling
# {
# var patrn=/^[0-9.]{1,20}$/;
# if (!patrn.exec(s)) return false
# return true
# }
# </pre>
# <br>
# <br><span>  Regular Expressions  </span>
# <br><pre name="code">"^\\d+$"  //  Non-negative integers  (  Positive integer   + 0)
# "^[0-9]*[1-9][0-9]*$"  //  Positive integer
# "^((-\\d+)|(0+))$"  //  Non-positive integer  (  Negative integer   + 0)
# "^-[0-9]*[1-9][0-9]*$"  //  Negative integer
# "^-?\\d+$"    //  Integer
# "^\\d+(\\.\\d+)?$"  //  Non-negative floating-point  (  Are floating-point   + 0)
# "^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$"
# //  Are floating-point
# "^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$"  //  Non Float  (  Negative float   + 0)
# "^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$"
# //  Negative float
# "^(-?\\d+)(\\.\\d+)?$"  //  Float
# "^[A-Za-z]+$"  //  26 English letters from the string
# "^[A-Z]+$"  //  26 English letters by the string composed of uppercase
# "^[a-z]+$"  //  The 26 lowercase letters of a string
# "^[A-Za-z0-9]+$"  //  26 numbers and a string of letters
# "^\\w+$"  //  .26 By the number of letters of the alphabet or underscore a string
# "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$"    //email  Address
# "^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$"  //url
# "^[A-Za-z0-9_]*$"
# </pre>
# <br>
# <br><span>  Detailed use of regular expressions  </span>
# <br>
# <br>  Introduction
# <br>
# <br>  In short, is a regular expression pattern matching and can be used to replace a powerful tool  .  Its role as  :
# <br>  A pattern test string. For example  ,  An input string can be tested to see whether the string exists in a phone number or a credit card number pattern pattern  .  This is called data validation  .
# <br>  Replacement text. To in the document using a regular expression to identify a specific text  ,  You can then all be removed, or replaced with other text  .
# <br>  Based on pattern matching to extract from the string of a string. Can be used in the text or to find specific text entry field  .
# <br>
# <br>  Basic Syntax
# <br>
# <br>  In the regular expression functions and role of initial understanding, we come to look at specific regular expression syntax  .
# <br>
# <br>  The general form of regular expressions as follows  :
# <br>
# <br>/love/     Which is located in "/" delimiter is the part between the object to be matched in the target pattern  .  Users want to find a match as long as the contents of the object model into the "/" delimiter can be between  .  In order to allow users to customize the model more flexible content, regular expressions offer a special  "  Metacharacters. "Refers to the so-called meta-character in the regular expression that has a special significance in the special characters  ,  Can be used to specify the leading characters  (  That is located in front of the character metacharacter  )  Appear in the target object model  .
# <br>  Including the more commonly used metacharacters  : "+", "*",  And   "?".
# <br>
# <br>"+"  Metacharacter requires its leading characters must appear in the target one or more times in a row  .
# <br>
# <br>"*"  Metacharacter requires its leading characters must appear in the target object is zero or repeatedly  .
# <br>
# <br>"?"  Per the provisions of its leading characters in the target object, the object must be zero or one successive  .
# <br>
# <br>  Now, let us look at the regular expression metacharacters specific applications  .
# <br>
# <br>/fo+/    Because the regular expression contains "+" metacharacter  ,  That can be targeted in the "fool", "fo", or   "football"  So in the letter f followed one or more consecutive letters  o  Match string  .
# <br>
# <br>/eg*/    Because the regular expression contains  "*"  Metacharacter indicates the target object   "easy", "ego",   Or "egg", etc. in letters  e  Followed by zero or more consecutive string of letters to match g  .
# <br>
# <br>/Wil?/    Because the regular expression contains a "?" Metacharacters ,  That can be targeted in the "Win", or  "Wilson",  So in the letter i followed consecutive zero or a letter  l  Match string  .
# <br>
# <br>  Sometimes do not know how many characters to match. In order to adapt to this uncertainty  ,  Regular expression support the concept of qualifiers. These qualifiers can specify a regular expression for a given number of components must be present to meet the match  .
# <br>
# <br>{n} n   Is a non-negative integer. Matching set   n   Times. For example,  ,'o{2}'   Can not match the "Bob" in the   'o',  But matches "food" in the two   o.
# <br>
# <br>{n,} n   Is a non-negative integer. At least match   n   Times. For example,  ,'o{2,}'   Can not match the "Bob" in the   'o',  But it can match "foooood" all the   o.'o{1,}'   Equivalent to   'o+'.'o{0,}'   Is equivalent to   'o*'.
# <br>
# <br>{n,m} m   And n are non-negative integers  ,  Which  n <= m.  Match at least n times and match up   m   Times. For example,  ,"o{1,3}"   Will match "fooooood" in the first three   o.'o{0,1}'   Equivalent to 'o?'. Please note that the comma and no space between the two numbers  .
# <br>
# <br>  In addition to metacharacters, the user can specify exactly match the object model in the frequency  .  For example,  ,/jim {2,6}/   Provisions of the above regular expression can match the character object m successive  2-6  Times, and thus  ,  The regular expression or with jimmy  jimmmmmy  String matching and other  .
# <br>  On how to use regular expressions have a preliminary understanding, we look at several other important use of meta characters  .
# <br><pre name="code">\s:  Used to match a single space character, including  tab  Key and line breaks  :
# \S:  In addition to a single space character used to match all the characters other than  :
# \d:  Used to match from 0 to  9  Figures  :
# \w:  Used to match letters, numbers, or underscore characters  :
# \W:  Used to match all  \w  The characters do not match  :
# . :  Used to match all characters except a newline  .
# </pre>
# <br>(  Help  :  We can  \s  And  \S  And  \w  And  \W  As the inverse operation of each other  )
# <br>  Here, we look through the examples how to use the regular expression metacharacters  .
# <br>/\s+/   The regular expression can be used to match the target object in one or more space characters  .
# <br>/\d000/   If we hand a complex financial statements, we can easily above the regular expression to find all the money amounting to thousands  .
# <br>  In addition to our meta-characters described above, the regular expression also has other special characters in a more unique  ,  The locator. Locator provides matching pattern for the target object appears in the position of  .   Including the more commonly used locator  : "^", "$", "\b"   And   "\B".
# <br><pre name="code">"^"  Locator provides matching pattern must appear at the beginning of the string in the target
# "$"  Locator provides matching pattern must appear at the end of the target object
# "\b"  Locator provides matching pattern must appear at the beginning or end of the target string one of the two boundary
# "\B"  Locator provides that the object must be in the target string matches the beginning and end within the boundaries of two  ,
#         Objects that match the target string neither the beginning nor the end of the string as the target  .
# </pre>
# <br>   Similarly, we can also  "^"  And  "$"  And  "\b"  And  "\B"  As the inverse operation of the two groups are mutually locator. For example,  : /^hell/   Because the regular expression contains  "^"  Website, and therefore can be targeted in   "hell", "hello"  Or "hellhound" at the beginning of the string match  . /ar$/   Because the regular expression contains   "$"  Website, and therefore can be targeted in   "car", "bar"  Or "ar" at the end of the string match  . /\bbom/   Because the regular expression pattern to   "\b"  Locator at the beginning, and therefore can be targeted in   "bomb",   Or "bom" at the beginning of the string match  ./man\b/   Because the regular expression pattern to  "\b"  Locator at the end, so it can be targeted in order to   "human", "woman"  Or "man" at the end of the string match  .
# <br>  To be able to set the user a more flexible pattern matching, regular expression matching mode allows users to specify a certain range is not limited to the specific character  .  For example,  :
# <br><pre name="code">/[A-Z]/    The regular expression will be from A to  Z  Capital letters within a match of any  .
# /[a-z]/    The regular expression to the will and from a  z  Range to match any lowercase letter  .
# /[0-9]/    The regular expression will work with from 0 to  9  Range to match any number  .
# /([a-z][A-Z][0-9])+/   The regular expression will work with any of the string of letters and numbers, such as  "aB0"   Other match  .
# </pre>
# <br>   It needs to note that the user is that you can use in regular expressions   "()"   String together  ."()"  Contains the contents of the symbol must appear in the target object. So  ,  The regular expression will not work with such as "abc" string matching, etc.  ,  Because "abc" in the last character is a letter rather than numbers  .
# <br>  If we want to achieve in the regular expression in a similar programming logic "or  "  Operation, a number of different modes in either one of the words to match  ,  Can use the pipe symbol   "|".  For example,  :/to|too|2/   The regular expression will be targeted in the "to", "too", or   "2"   Match  .
# <br>   There is also a regular expression operator the more commonly used, namely, negative character   "[^]".  With our previously described Locator   "^"   Different negator   "[^]"  Target object can not exist in the regulations stipulated in the mode string. For example,  :/[^A-C]/   The string will be targeted in addition to A, B, and  C  Matches any character other than. In general  ,  When  "^"  In   "[]"  When they are seen as the negation operator  :  When  "^"  In  "[]"  Outside, or not  "[]"  , Then the website should be viewed as  .
# <br>  Finally, when the user needs in the regular expression metacharacters added to the model  ,  And find the matching object, you can use the escape character  "\".  For example,  :/Th\*/    The regular expression will be the target object  "Th*"  Not "The" and so match  .
# <br>  In constructing a regular expression, you can like the same mathematical expression to evaluate  ,  That is, from left to right and in accordance with a priority order to evaluate  .  Priority is as follows  :
# <br><pre name="code">1  .  \   Escape
# 2  .  (), (?:), (?=), []   Parentheses and brackets
# 3  .  *, +, ?, {n}, {n,}, {n,m}   Qualifier
# 4  .  ^, $, \anymetacharacter   Location and sequence
# 5  .  |"  Or "operation
# </pre>
# <br>
# <br><span>  Use Case  </span>
# <br>  In JavaScript 1.2 with a powerful in  RegExp()  Objects can be used for regular expression matching operations  .  Which  test()  Method can test whether the target contains the matching pattern, and the corresponding return  true  Or false.
# <br>  We can write the following script using JavaScript  ,  Validate user input validity of e-mail address  .
# <br><pre name="code"><html>
# <head>
#   <script language="Javascript1.2">
#      <!-- start hiding
#      function verifyAddress(obj)
#      {
#       var email = obj.email.value;
#       var pattern =
# /^([a-zA-Z0-9_-])[email protected]([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
#       flag = pattern.test(email);
#       if(flag)
#       {
#        alert("Your email address is correct!");
#        return true;
#       }
#       else
#        {
#         alert("Please try again!");
#         return false;
#         }
#       }
#      // stop hiding -->
#     </script>
#   </head>
#   <body>
#    <form onSubmit="return verifyAddress(this);">
#     <input name="email" type="text">
#     <input type="submit">
#     </form>
#   </body>
# </html>
# </pre>
# <br>
# <br><span>  Regular Expression Object  </span>
# <br>  This object contains the regular expression pattern and showed a sign of how to apply the model  .
# <br><pre name="code">  Syntax   1 re = /pattern/[flags]
#   Syntax   2 re = new RegExp("pattern",["flags"])
# </pre>
# <br>  Parameters
# <br>re
# <br>  Required. Will be assigned to the regular expression pattern of the variable name  .
# <br>
# <br>Pattern
# <br>  Required. To use the regular expression pattern  .  If you use Syntax 1, with   "/"   Character separation mode. If syntax   2,  Cause the mode to use the quotation marks  .
# <br>
# <br>Flags
# <br>  Optional. If you use the syntax   2   Caused the flag to use the quotation marks  .  Flag can be used in combination with available  :
# <br><pre name="code">g (  Find all occurrences of text   pattern)
# i (  Ignore case  )
# m (  Multi-line search  )
# </pre>
# <br>
# <br><span>  Example  </span>
# <br>  The following example creates a regular expression object model and related marks  (re),  Shows you the usage of regular expression object. In this case,  ,  As a result of the regular expression object and the method used to match  :
# <br><pre name="code">function MatchDemo()
# {
# var r, re; //   Declare variables  .
# var s = "The rain in Spain falls mainly in the plain";
# re = new RegExp("ain","g"); //   Create a regular expression object  .
# r = s.match(re); //   To find a match in the string s  .
# return(r);
# }
# </pre>
# <br>
# <br>  Return Value  : ain,ain,ain,ain\\
# <br>  Property lastIndex property   | source   Properties  \\
# <br>  Method compile method   | exec   Methods   | test   Methods  \\
# <br>  Required version   3\\
# <br>  Please refer to the RegExp object   |   Regular expression syntax   | String   Object  \\
# <br>
# <br><span>exec   Methods  </span>
# <br>  Regular expression pattern used to run the search string, and returns the results containing the search an array  .
# <br>rgExp.exec(str)
# <br>
# <br>  Parameters
# <br>
# <br>rgExp
# <br>  Required. Contains the regular expression pattern and the available regular expression object logo  .
# <br>
# <br>str
# <br>  Required. In which to perform search   String   Object or text string  .
# <br>
# <br>  Help  \\
# <br>  If the exec method does not find a match  ,  It returns null. If it finds a match  ,  The exec method returns an array  ,  And update the global RegExp object's properties  ,  To reflect the matching results. Array  0  Element contains a complete match, while  1  To the n elements is contained in any one match appears in sub-matching  .  This is equivalent to global flag is not set   (g)   The match method  .
# <br>  If the regular expression to set the global flag, exec from a   lastIndex   The value indicates the location of start looking. If you do not set the global flags  ,exec   Ignore the value of lastIndex  ,  From the starting position to start the search string  .
# <br>
# <br>exec   Method returns an array has three properties, namely,   input.index   And lastIndex.Input property contains the entire search string  .Index   Property contains the search string to be matched by the sub-string position. LastIndex property contains the last character matched in the next position  .
# <br>
# <br>  Example  \\
# <br>  The following example illustrates the use of exec method  :
# <br><pre name="code">function RegExpTest()
# {
# var ver = Number(ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion())
# if (ver >= 5.5){ //   JScript version of the test  .
# var src = "The rain in Spain falls mainly in the plain.";
# var re = /\w+/g; //   Create a regular expression pattern  .
# var arr;
# while ((arr = re.exec(src)) != null)
# document.write(arr.index + "-" + arr.lastIndex + arr + "\t");
# }
# else{
# alert("  Please use an updated version of JScript  ");
# }
# }
# </pre>
# <br>
# <br>  Return Value  :0-3The 4-8rain 9-11in 12-17Spain 18-23falls 24-30mainly 31-33in 34-37the 38-43plain
# <br>
# <br>test   Methods  \\
# <br>  Returns a Boolean value  ,  It pointed out that the string is to find whether there are patterns  .
# <br>rgexp.test(str)
# <br>
# <br>  Parameters  \\
# <br>rgexp
# <br>  Required. Contains the regular expression pattern or the available regular expression object logo  .
# <br>
# <br>str
# <br>  Required. Which you want to test the search string  .
# <br>
# <br>  Help
# <br>test   Method checks whether the string there is a pattern, if it returns   true,  Otherwise it returns   false.
# <br>  Not help the global RegExp object's properties   test   Ways to modify the  .
# <br>
# <br>  Example
# <br>  The following example illustrates the use of test methods  :
# <br><pre name="code">function TestDemo(re, s)
# {
# var s1; //   Declare variables  .
# //   Check whether there is a regular expression string  .
# if (re.test(s)) //   Test whether there  .
# s1 = " contains "; // s   Include Pattern  .
# else
# s1 = " does not contain "; // s   Does not contain the pattern  .
# return("'" + s + "'" + s1 + "'"+ re.source + "'"); //   Returns the string  .
# }
# </pre>
# <br>
# <br>  Function call  :document.write (TestDemo(/ain+/ ,"The rain in Spain falls mainly in the plain."));
# <br>
# <br>  Return Value  :'The rain in Spain falls mainly in the plain.' contains 'ain+'
# <br>
# <br><span>match   Methods  </span>
# <br>  Use regular expression pattern to find the string implementation, and contains the search results returned as an array  .\\
# <br>stringObj.match(rgExp)
# <br>
# <br>  Parameters  \\
# <br>stringObj
# <br>  Required. Its search   String   Object or text string  .
# <br>
# <br>rgExp
# <br>  Required. To include regular expression pattern and the available regular expression object logo  .  Can also be included regular expression pattern and the available flags or string literal variable name  .
# <br>
# <br>  Help  \\
# <br>  If the method does not find a match match  ,  Returns null. If a match is found returns an array and update the global   RegExp   Object properties to reflect the matching results  .
# <br>match   Method returns an array has three properties  :input.index   And lastIndex.Input property contains the entire search string is  .Index  Property contains the search string in the whole match was sub-string position. LastIndex property contains the last match of the last character position of the next  .
# <br>  If you do not set the global flags   (g),  0 array element contains the entire match  ,  The first 1 to   n   Element contains the match there had been a child of any match. This is equivalent to the global flag is not set   exec   Method. If you set a global flag  ,  Element 0   n   Contains all matches  .
# <br>
# <br>  Example  \\
# <br>  The following example demonstrates the use of match method  :
# <br><pre name="code">function MatchDemo()
# {
# var r, re; //   Declare variables  .
# var s = "The rain in Spain falls mainly in the plain";
# re = /ain/i; //   Create a regular expression pattern  .
# r = s.match(re); //   Try to match the search string  .
# return(r); //   Back to the first occurrence of "ain" in place  .
# }
# </pre>
# <br>  Return Value  :ain
# <br>
# <br>  This example shows the flag set with g   match   Method of use  .
# <br><pre name="code">function MatchDemo()
# {
# var r, re; //   Declare variables  .
# var s = "The rain in Spain falls mainly in the plain";
# re = /ain/ig; //   Create a regular expression pattern  .
# r = s.match(re); //   Try to match the search string  .
# return(r); //   Returns an array containing all   "ain"
# //   There's four matches  .
# }
# </pre>
# <br>  Return Value  :ain,ain,ain,ain
# <br>
# <br>  The above few lines of code demonstrates the method of the string match the usage of words  .
# <br><pre name="code">var r, re = "Spain";
# r = "The rain in Spain".replace(re, "Canada");
# return r;
# </pre>
# <br>  Return Value  :The rain in Canada
# <br>
# <br><span>search   Methods  </span>
# <br>  Back to the contents of the regular expression match to find the location of the first sub-string  .
# <br>
# <br>stringObj.search(rgExp)
# <br>
# <br>  Parameters  \\
# <br>stringObj
# <br>  Required. Which you want to search on   String   Object or text string  .
# <br>
# <br>rgExp
# <br>  Required. Contains the regular expression pattern and the available regular expression object logo  .
# <br>
# <br>  Help
# <br>
# <br>search   Methods indicate the existence of a corresponding match. If a match is found  ,search   Method returns an integer value, indicating the beginning of the string matches the offset distance  .  If no match is found, it returns   -1.
# <br>
# <br>  Example  \\
# <br>  The following example demonstrates the use of search methods  .
# <br><pre name="code">function SearchDemo()
# {
# var r, re; //   Declare variables  .
# var s = "The rain in Spain falls mainly in the plain.";
# re = /falls/i; //   Create a regular expression pattern  .
# r = s.search(re); //   Search String  .
# return(r); //   Return Boolean results  .
# }
# </pre>
# <br>  Return Value  :18
# <br>
# <br>
# <br><span>  Regular expression syntax  </span>
# <br>  A regular expression is a character from the ordinary  (  For example, a character to   z)  And special characters  (  Called meta-characters  )  Composed of text mode. The model described in the main text to find the time to be matched one or more strings  .  Regular Expressions as a template, the search for a character string pattern matching by  .
# <br>
# <br>  Here are some you might encounter examples of regular expressions  :
# <br><pre name="code">JScript VBScript   Match
# /^\[ \t]*$/ "^\[ \t]*$"   Match a blank line  .
# /\d{2}-\d{5}/ "\d{2}-\d{5}"   An ID number is verified by a  2  Digits, a hyphen and a  5  Digits  .
# /<(.*)>.*<\/\1>/ "<(.*)>.*<\/\1>"   Matches a HTML tag  .
# </pre>
# <br>
# <br>  The following table metacharacters and regular expressions in the context of a complete list of acts  :
# <br>
# <br>  Character Description
# <br>\   The next character is marked as a special character. Or a literal character  .  Or a backward reference  .  Or an octal escape character. Eg  ,'n'   Matches the character   "n".'\n'   Matches a newline. Sequence   '\\'   Match   "\"   The   "\("   The match   "(".
# <br>
# <br>^   Matches the beginning of the string. If you set   RegExp   Multiline property of the object  ,^   Also match   '\n'   Or  '\r'   Position after  .
# <br>
# <br>$   Match the input end of the string. If you set  RegExp   Multiline property of the object  ,$   Also match   '\n'   Or  '\r'   Position before  .
# <br>
# <br>*   Matches the preceding subexpression zero or more times. For example,  ,zo*   Matches "z" and   "zoo". *   Equivalent to  {0,}.
# <br>
# <br>+   Matches the preceding subexpression one or more times. For example,  ,'zo+'   Matches "zo" and   "zoo",  But can not match the "z". + Is equivalent to   {1,}.
# <br>
# <br>?   Matches the preceding subexpression zero or one. For example,  ,"do(es)?"   Can match "do" or   "does"   The "do".? Equivalent   {0,1}.
# <br>
# <br>{n} n   Is a non-negative integer. Matching set   n   Times. For example,  ,'o{2}'   Can not match the "Bob" in the   'o',  But matches "food" in the two   o.
# <br>
# <br>{n,} n   Is a non-negative integer. At least match  n   Times. For example,  ,'o{2,}'   Can not match the "Bob" in the   'o',  But it can match "foooood" all the   o.'o{1,}'   Equivalent to   'o+'.'o{0,}'   Is equivalent to   'o*'.
# <br>
# <br>{n,m} m   And n are non-negative integers  ,  Which  n <= m.  Match at least n times and match up   m   Times. Liu  , "o{1,3}"   Will match "fooooood" in the first three   o.'o{0,1}'   Equivalent to 'o?'. Please note that the comma and no space between the two numbers  .
# <br>
# <br>?   When this character immediately follows any of the other qualifier   (*, +, ?, {n}, {n,}, {n,m})   Back when the non-greedy matching pattern  .  Non-greedy pattern matches as little as possible of the search string, the default greedy pattern matches as much as possible the search string  .  For example, for strings   "oooo",'o+?'   Will match a single "o", and   'o+'   Will match all   'o'.
# <br>
# <br>.   In addition to matching   "\n"   Beyond any single character. To match, including   '\n'   Any character, including, use as   '[.\n]'   Model  .
# <br>(pattern)   Match the pattern and get the match  .  Matches obtained from the resulting Matches collection can be  ,  Used in VBScript   SubMatches   Collection, in  JScript   In use   $0-$9   Properties. To match parentheses characters  ,  Use   '\('   Or  '\)'.
# <br>
# <br>(?:pattern)   Match the pattern but does not match the results obtained  ,  That this is a non-access match, do not be stored for later use  .  This use of "or  "   Character   (|)   To combine the various parts of a model is useful. For example,  , 'industr(?:y|ies)   Is a ratio of   'industry|industries'   More simple expression  .
# <br>
# <br>(?=pattern)   Positive pre-investigation, in any match   pattern   The beginning of the string matches the search string. This is a non-access match  ,  That is, the match does not need access to for future use  .  For example,  , 'Windows (?=95|98|NT|2000)'   Matches "Windows 2000" in   "Windows" ,  But can not match the "Windows 3.1" in the   "Windows".  Pre-check does not consume characters, that is  ,  In a match occurs, immediately after the last match to start the next match search  ,  Rather than from the characters that contains pre-investigation began after  .
# <br>
# <br> (?!pattern)   Negative pre-investigation, in any match   Negative lookahead matches the search string at any point where a string not matching pattern   The beginning of the string matches the search string. This is a non-access match  ,  That is, the match does not need access to for future use  .  For example,  'Windows (?!95|98|NT|2000)'   Matches "Windows 3.1" in the   "Windows",  But can not match the "Windows 2000" in   "Windows".  Pre-check does not consume characters, that is  ,  In a match occurs, immediately after the last match to start the next match search  ,  Rather than from the characters that contains pre-investigation began after
# <br>
# <br>x|y   Match x or   y.  For example,  ,'z|food'   Matches "z" or   "food".'(z|f)ood'   The match "zood" or   "food".
# <br>
# <br>[xyz]   Character set. Matches any character contained in  .  For example,  , '[abc]'   Can match the "plain" in the   'a'.
# <br>
# <br>[^xyz]   Negative character set. Matches any character not included in  .  For example,  , '[^abc]'   Can match the "plain" in the  'p'.
# <br>
# <br>[a-z]   Range of characters. Matches any character within the specified range  .  For example,  ,'[a-z]'   Can match the 'a' to   'z'   Anywhere within the lower-case alphabetic characters  .
# <br>
# <br>[^a-z]   Negative character ranges. Not match any arbitrary character within the specified range  .  For example,  ,'[^a-z]'   Can not match any 'a' to   'z'   Any character within the  .
# <br>
# <br>\b   Match a word boundary, but also refers to the location of words and spaces between  .  For example,  , 'er\b'   Can match "never" in the   'er',  But can not match the "verb" in   'er'.
# <br>
# <br>\B   Match non-word boundary  .'er\B'   Can match the "verb" in   'er',  But will not match "never" in the  'er'.
# <br>
# <br>\cx   Match control characters specified by the x  .  For example,  , \cM   Matches a Control-M or carriage return  . x   The value must be AZ or   a-z   One. Otherwise,  ,  Will be treated as a literal c   'c'   Character  .
# <br>
# <br>\d   Matches a digit character. Is equivalent to   [0-9].
# <br>
# <br>\D   Match a non-numeric characters. Is equivalent to   [^0-9].
# <br>
# <br>\f   Matches a form feed character. Is equivalent to   \x0c   And   \cL.
# <br>
# <br>\n   Matches a newline. Is equivalent to   \x0a   And   \cJ.
# <br>
# <br>\r   Matches a carriage return. Is equivalent to   \x0d   And   \cM.
# <br>
# <br>\s   Match any whitespace characters, including spaces  .  Tab. Formfeeds etc.  .  Equivalent to   [ \f\n\r\t\v].
# <br>
# <br>\S   Matches any non whitespace character. Is equivalent to   [^ \f\n\r\t\v].
# <br>
# <br>\t   Matches a tab character. Is equivalent to   \x09   And   \cI.
# <br>
# <br>\v   Matches a vertical tab. Is equivalent to   \x0b   And   \cK.
# <br>
# <br>\w   Match any word character including underscore. Is equivalent to  '[A-Za-z0-9_]'.
# <br>
# <br>\W   Matches any non word character. Is equivalent to   '[^A-Za-z0-9_]'.
# <br>
# <br>\xn   Match n, where   n   As a hexadecimal escape value. Hexadecimal escape value must be determined by two digits long  .  For example,  , '\x41'   Match   "A".'\x041'   Is equivalent to   '\x04' & "1".  Regular expressions can be used in ASCII encoding  ..
# <br>
# <br>\num   Match num, where   num   Is a positive integer. On a reference to the matching obtained  .  For example,  ,'(.)\1'   Matches two consecutive identical characters  .
# <br>
# <br>\n   Identifies an octal escape value or a back reference. If   \n   Get at least one previous sub-expression n  ,  After the reference to the n  .  Otherwise, if   n   Octal numbers   (0-7),  Then n is an octal escape value  .
# <br>
# <br>\nm   Identifies an octal escape value or a back reference. If   \nm   At least before is preceded by at least nm were obtained was sub-expression  ,  Nm for the post is the reference  .  If   \nm   Get at least before the n-  ,  The n word as a heel   m   Backward reference. If the preceding conditions are not met  ,  If n and   m   Octal numbers are   (0-7),  The   \nm   Matches octal escape value   nm.
# <br>
# <br>\nml   If n is an octal number   (0-3),  And m and   l   Octal numbers are   (0-7),  Matches octal escape value is   nml.
# <br>
# <br>\un   Match n, where   n   Is a use of four hexadecimal digits of the Unicode characters  .  For example,  , \u00A9   Match the copyright symbol   (?).
# <br>
# <br>
# <br><span>  Order of priority  </span>
# <br>  In constructing a regular expression, you can like the same mathematical expression to evaluate  ,  That is, from left to right and in accordance with a priority order to evaluate  .
# <br>
# <br>  The following table from the highest priority to lowest priority lists the various regular expression operators in order of priority  :
# <br><pre name="code">  Operator Description
# \   Escape
# (), (?:), (?=), []   Parentheses and brackets
# *, +, ?, {n}, {n,}, {n,m}   Qualifier
# ^, $, \anymetacharacter   Location and sequence
# | "  Or "operation
# </pre>
# <br>
# <br>  Ordinary characters
# <br>
# <br>  General character of all those who have not explicitly specified as per print and non-printing characters characters. This includes all uppercase and lowercase alphabetic characters  ,  All figures, all the punctuation marks and symbols  .
# <br>
# <br>  The simplest regular expression is a single ordinary characters, you can match the search string in the character itself  .  For example, the single-character mode   'A'   Can match the search string appear anywhere in the letter 'A'. Here are some single-character regular expression pattern of the sample  :
# <br><pre name="code">/a/
# /7/
# /M/
# </pre>
# <br>  VBScript equivalent for the single character regular expression  :
# <br><pre name="code">"a"
# "7"
# "M"
# </pre>
# <br>  You can combine multiple single character to get a larger expression. For example,  ,  The following JScript regular expression is nothing  ,  Is through the combination of single-character expression 'a'. '7 'And   'M'   Created out of an expression  .
# <br>
# <br>/a7M/
# <br>  VBScript equivalent expression for  :
# <br>
# <br>"a7M"
# <br>  Please note that there is no connection operator. Need to do is a character on the back of another character  .
# <br>
# <br>
相关文章
  • javascript regular expression [Z] 2010-10-16

    JS regular expressions / / Check whether all the numbers function isDigit (s) { var patrn = / ^ [0-9] {1,20} $ /; if (! patrn.exec (s)) return false return true } / / Check login name: Enter only 5-20 with a letter, can be a string with digital ,"_&q

  • JavaScript regular expression syntax table 2010-07-10

    JavaScript regular expression syntax Form Release date :2009-04-29 Source: Internet Author: Anonymous Character Description \ Mark the next character is special character or text. For example, "n" and the character "n" match. "\ N

  • javascript regular expression combat 2010-06-13

    The end of regular expression matching the number of actual combat uniform spaces according to the number string is not the phone number digits are the phone numbers using regular expression regular expression string to achieve Shan Chu spaces Restri

  • Refresher javascript regular expression (ZT) 2010-07-15

    Javascript regular expression for a basic knowledge of 1 javascript regular object creation and usage Javascript regular expression statement var reCat = new RegExp ("cat"); You can also var reCat = / cat /; / / Perl style (recommended) 2 learn

  • Application of JavaScript regular expression 2010-07-25

    Application of JavaScript regular expression Application of the regular expression RegExp object 1, create a regular expression: var oRexp=new REgExp(parrern[,flag]); flag: Available in four values , g Represents a global match detection i Indicates

  • javascript regular expression study (reproduced) 2010-10-29

    JavaScript form validation Age JavaScript form validation of age, to determine whether an input of age, achieved through regular expressions. Javascript code / / Check the age of function isAge (str) { var mydate = new Date; var now = mydate.getFullY

  • Daquan JavaScript regular expression validation 2010-12-07

    Daquan JavaScript regular expression validation Chinese characters matching the regular expression: [\ u4E00-\ uFA29] Comment: The match is a headache for the Chinese really do, with this expression is easier to handle Matching double-byte characters

  • Javascript Regular Expression Notes (Revised Edition) 2010-07-01

    ^ The caret (^) tells the regular expression that the character must not match the characters to follow. For example to match all but a, or b characters, character classes can write [^ ab] ^ Locator provides matching pattern must be present in the ta

  • [Reprinted] Javascript regular expression notes 2010-08-17

    ^ The caret (^) tells the regular expression that the character must not match the characters to follow. For example to match all but a or b of the characters, character classes can write [^ ab] ^ Locator provides matching pattern must appear at the

  • JavaScript regular expression 2009-10-11

    Long time no javascript regular expressions used, and today a number of projects needed to meet the authentication problem is a long time to forget a lot of really useless things. Placed on a validation date YYYY-MM-DD hh: mm the expression / / Deter

  • JAVASCRIPT regular expression (5) 2008-12-28

    exec method Xiangjie exec method returns the value of exec method returns the results in fact do not match the string, but an object, simply change it execReg function, to do an experiment can prove this point: Java code <script type="text/javascr

  • Commonly used javascript regular expression based validation code text box 2010-03-31

    1, can not be empty <input type="text""if(this.value.replace(/^ +| +$/g,'')=='')alert(' Cannot be empty !')"> 2, can only enter numbers in English and <input"if(/[^0-9a-zA-Z]/g.test(value))alert(' There is wrong ')"&

  • JavaScript regular expression exec, test, match, replace, split 2010-04-29

    <script LANGUAGE="javascript"> var u = "http://msdn.microsoft.com:80/scripting/default.htm"; var s = / (\ w +): \ / \ /([^/:]+)(: \ d *)?([^# ]*)/; var a = s.exec (u); for (i = 1; i <a.length; i + +) ( alert (a [i]); ) </ S

  • A collection of JavaScript regular expression 2010-05-31

    Chinese characters matching the regular expression: [u4e00-u9fa5] Comment: The match is a headache for the Chinese really do, with this expression is easier to handle Matching double-byte characters (including Chinese characters included): [^ x00-xff

  • JavaScript regular expression validation Daquan 2010-08-26

    Chinese characters matching the regular expression: [u4e00-u9fa5] Comment: The match is a headache for the Chinese really do, with this expression is easier to handle Matching double-byte characters (including Chinese characters included): [^ x00-xff

  • JavaScript regular expression object's properties and methods 2010-09-29

    Regular expression object's properties and methods Predefined regular expressions have the following static properties: input, multiline, lastMatch, lastParen, leftContext, rightContext and $ 1 to $ 9. Which can be pre-set input and multiline. The va

  • JavaScript regular expression validation 2010-10-19

    Chinese characters matching the regular expression: [u4e00-u9fa5] Comment: The match is a headache for the Chinese really do, with this expression is easier to handle Matching double-byte characters (including Chinese characters included): [^ x00-xff

  • JavaScript regular expression (to) 2010-11-17

    Create a regular expression The first method: var reg = / pattern /; The second method: var reg = new RegExp ('pattern'); Regular expression exec method Introduction Syntax: reg.exec (str); Where str is a regular expression to perform the target stri

  • Commonly used in JavaScript regular expression validation 2010-12-31

    Here are my collection of some of the more commonly used regular expression, because usually in the form validation when possible, used more. Special issue and let you friends to use. Ha ha. Chinese characters matching the regular expression: [u4e00-

  • javascript regular expression in the greed mode and a number of issues such as non-greedy mode 2010-03-19

    1, greedy mode: According to the matching string and regular expression matching as much as possible, a greedy matching models such as: / a \ d + / that can match the first letter of the following as a number of figures, this does not restrict or ano