Regular Expression Reference

2010-11-08  来源:本站原创  分类:Web  人气:141 

/ / 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 ,"_","."
Java code
function isRegisterUserName (s)
{
var patrn = / ^ [a-zA-Z] {1} ([a-zA-Z0-9 ]|[._]){ 4,19} $ /;
if (! patrn.exec (s)) return false
return true
}

/ / Check User Name: 1-30 months can only enter the string starts with a letter
Java code
function isTrueName (s)
{
var patrn = / ^ [a-zA-Z] {1,30} $ /;
if (! patrn.exec (s)) return false
return true
}
}}

/ / Verify password: 6-20 can only enter letters, numbers, underscores
<pre name="code"> function isPasswd (s)
{
var patrn = / ^ (\ w) {6,20} $ /;
if (! patrn.exec (s)) return false
return true
}
</ Pre>
<br>
<br> / / check normal telephone and fax numbers: You 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: You 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 expression </ span>
<br> <pre name="code"> "^ \ \ d + $" / / non-negative integers (positive integers + 0)
"^ [0-9] * [1-9] [0-9] * $" / / a positive integer
"^((- \ \ D +) | (0 +))$" / / non-positive integer (negative integer + 0)
"^ - [0-9] * [1-9] [0-9] * $" / / negative integers
"^ -? \ \ D + $" / / integer
"^ \ \ D + (\ \. \ \ D +)?$" / / non-negative floating point numbers (positive float + 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 +)?))$" / / floating-point non-positive (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 +)?$" / / floating point
"^ [A-Za-z] + $" / / by the 26 English letters of the string
"^ [AZ] + $" / / by the 26 English letters uppercase a string
"^ [Az] + $" / / by the 26 English letters lowercase a string
"^ [A-Za-z0-9] + $" / / 26 by the numbers and a string of letters
"^ \ \ W + $" / / by the numbers, 26 English letters 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> use regular expressions Detailed </ span>
<br>
<br> Introduction
<br>
<br> short, is a regular expression pattern matching and can be used to replace a powerful tool. Its role as follows:
<br> test string a pattern. For example, an input string can be tested to see whether there is in the string model a phone number or a credit card number pattern. This is called data validation.
<br> replacement text. May in the document using a regular expression to identify a specific text, and then can all be removed, or replaced with other text.
<br> from the string based on pattern matching to extract a substring. Can be used in the text or to find a specific text entry field.
<br>
The basic syntax <br>
<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." The so-called meta-characters are those in the regular expression special characters with special meaning, can be used to specify the leading characters (ie characters in front of the characters in the element) appear in the target object model.
<br> more commonly used meta-characters are: "+", "*" 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 appear zero or one row.
<br>
<br> Now, let us look at the regular expression meta-character is given.
<br>
<br> / fo + / because the regular expression contains "+" meta characters that can be targeted in a "fool", "fo", or "football" and so in the letter f followed one or more consecutive letters o the strings match.
<br>
<br> / eg * / because the regular expression contains "*" meta characters that can be targeted in the "easy", "ego", or "egg", etc. appear in the letter e followed by zero or more consecutive letter g strings match.
<br>
<br> / Wil? / because the regular expression contains a "?" meta characters that can be targeted in the "Win", or "Wilson", such as the letter i in the back of successive zero or a letter l, string match.
<br>
<br> sometimes do not know how many characters to match. In order to adapt to this uncertainty, the 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. Match to determine the n times. For example, 'o {2}' does not match the "Bob" in the 'o', but can match the "food" in the two o.
<br>
<br> {n,} n is a non-negative integer. Match at least n times. For example, 'o {2,}' does not match the "Bob" in the 'o', but it can match "foooood" all of the o. 'O {1,}' is equivalent to 'o +'. 'O {0,}' is equivalent to 'o *'.
<br>
<br> {n, m} m and n are non-negative integers, where n <= m. Match at least n times and match up to m times. For example, "o {1,3}" will match "fooooood" in the first three o. 'O {0,1}' is equivalent to 'o?'. Note that the comma and no spaces between the two numbers.
<br>
<br> addition to metacharacters, the user can specify exactly match the object model in the frequency. For example, / jim {2,6} / the provisions of the above character regular expression match object m can occur 2-6 times in a row, so the above regular expression can be a string with jimmy or jimmmmmy other match.
<br> on how to use regular expressions have a preliminary understanding, we look at several other important metacharacter is used.
<br> <pre name="code"> \ s: used to match a single space character, including the tab key and line breaks;
\ S: In addition to a single space character used to match all the characters outside;
\ D: to match the number from 0 to 9;
\ W: to match letters, numbers or underscore characters;
\ W: for all matches \ w does not match the characters;
.: Used to match all characters except a newline.
</ Pre>
<br> (Note: we can put \ s and \ S and \ w and \ W as the inverse 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 the total worth of all payments.
<br> addition to our meta-characters described above, the regular expression also has other special characters in a more unique, the website. Locator provides matching pattern for the target object appears in the position. Website includes more commonly used: "^", "$", "\ b" and "\ B".
<br> <pre name="code"> "^" website provides matching pattern must be present in the target string begins with "$" website provides matching pattern must be present in the target object at the end of "\ b" matches the website provides mode must be present in the target string at the beginning or end of one of the two boundaries "\ B" website is provided in the target object must match the beginning and end of the string within the two boundaries,
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 two mutually inverse operations locator. For example: / ^ hell / because the regular expression contains "^" website, and therefore can be targeted in a "hell", "hello" or "hellhound" at the beginning of the string match. / Ar $ / because the regular expression contains "$" website, so you can target object to "car", "bar" or "ar" ending the string match. / \ Bbom / because the regular expression pattern with "\ b" website at the beginning, and therefore can be targeted in a "bomb", or "bom" at the beginning of the string match. / Man \ b / as in the regular expression pattern "\ b" website at the end, and therefore can be targeted in a "human", "woman" or "man" at the end of the string match.
<br> order to set the user a more flexible pattern matching, regular expression matching mode allows users to specify a certain range is not limited to specific characters. For example:
<br> <pre name="code"> / [AZ] / the regular expression will work with the range from A to Z of any capital letters match.
/ [Az] / the regular expression will work with the range from a to z match any lowercase letter.
/ [0-9] / the regular expression will work with the range from 0 to 9 to match any number.
/ ([Az] [AZ] [0-9]) + / The regular expression will work with any of the string of letters and numbers, such as "aB0" and other matches.
</ Pre>
This needs attention <br> point is that you can use a regular expression "()" to string together. "()" Contains the contents of the symbol must appear in the target object. Therefore, the regular expression will not work with such as "abc" matches the string such as "abc" as the last character in the alphabet rather than numbers.
<br> if we want to achieve in the regular expression in a similar programming logic "or" operation, in a number of different modes to match either one, you can use the pipe symbol "|". For example: / to | too | 2 / the regular expression will be targeted in the "to", "too", or "2" to match.
<br> regular expression and a more commonly used operators, that is, negative character "[^]"。 With our previously described Locator "^" different, negate the provisions of the target character "[^]" mode can not exist in the specified string. For example: / [^ AC] / the string will be targeted in addition to A, B, and C matches any character other than. In general, when the "^" appears in the "[]" in denial when it is viewed as operator; and when the "^" in the "[]" than, or not "[]", then should be viewed as Locator.
<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 targeted in the "Th *" and not "The" other match.
<br> in constructing regular expressions, you can find as to the value of the same mathematical expression, that is, from left to right and in accordance with a priority order is evaluated. Priority is as follows:
<br> <pre name="code"> 1. \ Escape character
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 in with a powerful RegExp () object that can be used for regular expression matching operation. One of the test () method can test whether the target contains the matching pattern, and the corresponding returns true or false.
<br> we can write the following JavaScript script to verify user input validity of email addresses.
<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 the application mode.
<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 separating mode. If syntax 2, causing the mode to use the quotation marks.
<br>
<br> Flags
<br> optional. 2 If you use the syntax to use quotation marks to flag causes. Flag can be used in combination, can be used are:
<br> <pre name="code"> g (full text search for all occurrences of pattern)
i (ignore case)
m (multi-line search)
</ Pre>
<br>
<br> <span> Example </ span>
<br> The following example creates a regular expression pattern and related marks the object (re), to show you the usage of regular expression objects. In this case, as a result of the regular expression object is then used to match methods:
<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 regular expression object.
r = s.match (re); / / Find the string s matches.
return (r);
}
</ Pre>
<br>
<br> return value: ain, ain, ain, ain \ \
<br> property lastIndex property | source attributes \ \
<br> method compile methods | exec method | test method \ \
<br> Version 3 \ \
<br> see RegExp Object | Regular Expression Syntax | String object \ \
<br>
<br> <span> exec method </ 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 flags object.
<br>
<br> str
<br> Required. Search in which the implementation of String object or string literal.
<br>
<br> Description \ \
<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 matches. 0 array element contains a complete match, 1 to n elements is contained in any one match appears in sub-match. This is equivalent to not set the global flag (g) of the match method.
<br> If the regular expression to set the global flag, exec from a location indicated by the value of lastIndex start looking. If you do not set the global flags, exec lastIndex ignored the value of the starting position from the string to start the search.
<br>
<br> exec method returns an array has three properties, namely, input, index, and lastIndex. Input attribute contains the entire search string. Index attribute contains the entire search string is matched substring position. LastIndex property contains the last character matched in the next position.
<br>
<br> example \ \
<br> The following example illustrates the exec method:
<br> <pre name="code"> function RegExpTest ()
{
var ver = Number (ScriptEngineMajorVersion () + "." + ScriptEngineMinorVersion ())
if (ver> = 5.5) {/ / test the JScript version.
var src = "The rain in Spain falls mainly in the plain.";
var re = / \ w + / g; / / Create 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 method \ \
<br> returns a Boolean value, it was pointed out that the existence of a string search pattern.
<br> rgexp.test (str)
<br>
<br> parameters \ \
<br> rgexp
<br> Required. Contains the regular expression pattern or regular expression can mark the object.
<br>
<br> str
<br> Required. On which to test the search string.
<br>
<br> Help
<br> test method to check whether the string there is a pattern, if it returns true, otherwise returns false.
<br> not help the global RegExp object's properties to modify the test method.
<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 exists.
s1 = "contains"; / / s contains the pattern.
else
s1 = "does not contain"; / / s does not contain the pattern.
return ("'" + s + "'" + s1 + "'" + re.source + "'"); / / return 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 method </ span>
<br> use the regular expression pattern to find the string implementation, and contains the search results as array. \ \
<br> stringObj.match (rgExp)
<br>
<br> parameters \ \
<br> stringObj
<br> Required. String find its object or string literal.
<br>
<br> rgExp
<br> Required. Contains the regular expression pattern and the available regular expression flags object. Can also be included regular expression pattern and the available flags or string literal variable name.
<br>
<br> Description \ \
<br> If the match method does not find a match, return null. If a match is found returns an array and update the global RegExp object's properties to reflect the matches.
<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 in the last character to the next location.
<br> If you do not set the global flag (g), the array element 0 contains the entire match, 1 to n elements contains a 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, elements 0 to n is included in all matches.
<br>
<br> example \ \
<br> match the following example demonstrates the use of methods:
<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 regular expression pattern.
r = s.match (re); / / try to match the search string.
return (r); / / returns the first occurrence of "ain" place.
}
</ Pre>
<br> return value: ain
<br>
<br> This example illustrates the match with the g flag set 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 / ig; / / Create regular expression pattern.
r = s.match (re); / / try to match the search string.
return (r); / / returns an array containing all the "ain"
/ / There's four matches.
}
</ Pre>
<br> return value: ain, ain, ain, ain
<br>
<br> few lines of code above shows the text string match method.
<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 method </ span>
<br> return 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 a String object or string literal.
<br>
<br> rgExp
<br> Required. Contains the regular expression pattern and the available regular expression flags object.
<br>
<br> Help
<br>
<br> search methods specify whether there is a corresponding match. If a match is found, search method returns an integer value indicating the match from the beginning of the string offset. 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 regular expression pattern.
r = s.search (re); / / search string.
return (r); / / returns Boolean results.
}
</ Pre>
<br> return value: 18
<br>
<br>
<br> <span> regular expression syntax </ span>
<br> a regular expression is by ordinary characters (for example the character a to z) and special characters (called metacharacters) 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 model and the search for a character string to match.
<br>
<br> may encounter here are some regular expression examples:
<br> <pre name="code"> JScript VBScript match
/ ^ \ [\ T] * $ / "^ \ [\ t] * $" matches a blank line.
/ \ D {2} - \ d {5} / "\ d {2} - \ d {5}" verify a ID number is composed of a 2-digit, a hyphen and a 5-digits.
/<(.*)>.*< \ / \ 1> / "<(.*)>.*< \ / \ 1> "matches an HTML tag.
</ Pre>
<br>
<br> following table metacharacters and regular expressions in the context of the behavior of a complete list:
<br>
<br> Character Description
<br> \ the next character is marked as a special character, or a literal character, or a back reference, or an octal escape. For example, 'n' matches the character "n". '\ N' matches a newline character. Sequence '\ \' matches "\" and "\ (" the match "(."
<br>
<br> ^ Matches the beginning of the string. If you set the RegExp object's Multiline property, ^ also matches '\ n' or '\ r' after the location.
<br>
<br> $ Matches the end of the string. If you set the RegExp object's Multiline property, $ also matches '\ n' or '\ r' previous position.
<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>? match the previous subexpression zero or one. For example, "do (es)?" To match "do" or "does" in the "do". ? Equivalent to {0,1}.
<br>
<br> {n} n is a non-negative integer. Match to determine the n times. For example, 'o {2}' does not match the "Bob" in the 'o', but can match the "food" in the two o.
<br>
<br> {n,} n is a non-negative integer. Match at least n times. For example, 'o {2,}' does not match the "Bob" in the 'o', but it can match "foooood" all of the o. 'O {1,}' is equivalent to 'o +'. 'O {0,}' is equivalent to 'o *'.
<br>
<br> {n, m} m and n are non-negative integers, where n <= m. Match at least n times and match up to m times. Liu, "o {1,3}" will match "fooooood" in the first three o. 'O {0,1}' is equivalent to 'o?'. Note that the comma and no spaces between the two numbers.
<br>
<br>? When the characters followed in any 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 the string "oooo", 'o +?' Will match a single "o", while 'o +' matches all 'o'.
<br>
<br>. matching except "\ n" beyond any single character. To match, including '\ n' any character, including, use as '[. \ N]' model.
<br> (pattern) matches the pattern and to obtain the match. Match can be obtained from the resulting Matches collection are in VBScript using SubMatches collection in JScript, use the $ 0 ... $ 9 properties. To match parentheses characters, use '\ (' or '\)'.
<br>
<br> (?: pattern) matches 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 brief expressions.
<br>
<br> (? = pattern) Positive pre-investigation, in any matching string pattern matches the beginning of the search string. This is a non-access match, that is, the match does not need to get for later use. For example, 'Windows (? = 95 | 98 | NT | 2000)' matches "Windows 2000" in the "Windows", but can not match the "Windows 3.1" in the "Windows". Pre-check does not consume characters, that is, in a match occurs, the last match in the next match started immediately after the search, rather than from the characters that contains pre-investigation after the start.
<br>
<br> (?! pattern) negative pre-investigation, in any match Negative lookahead matches the search string at any point where a string not matching pattern string matches the beginning of the search string. This is a non-access match, that is, the match does not need to get for later use. For example 'Windows (?! 95 | 98 | NT | 2000)' matches "Windows 3.1" in the "Windows", but can not match the "Windows 2000" in the "Windows". Pre-check does not consume characters, that is, in a match occurs, the last match in the next match started immediately after the search, rather than from the characters that contains pre-investigation began after
<br>
<br> x | y matches x or y. For example, 'z | food' matches "z" or "food". '(Z | f) ood' the match "zood" or "food".
<br>
<br> [xyz] character set. Match any of the characters included. For example, '[abc]' will match "plain" in the 'a'.
<br>
<br> [^ xyz] negative character set. Matches any character not included. For example, '[^ abc]' will match "plain" in the 'p'.
<br>
<br> [az] character range. Matches any character within the specified range. For example, '[az]' will match 'a' to 'z' anywhere within the lower-case alphabetic characters.
<br>
<br> [^ az] the scope of a negative character. Does not match any arbitrary character within the specified range. For example, '[^ az]' matches any not 'a' to 'z' within the scope of any character.
<br>
<br> \ b matches a word boundary, that is, that space between words and location. For example, 'er \ b' to match the "never" in the 'er', but can not match the "verb" in the 'er'.
<br>
<br> \ B matches non-word boundary. 'Er \ B' matches "verb" in the 'er', but will not match "never" in the 'er'.
<br>
<br> \ cx matches the control specified by the x character. For example, \ cM matches a Control-M or carriage return. x The value must be AZ or az. Otherwise, c as a literal 'c' character.
<br>
<br> \ d Matches a digit character. Equivalent to [0-9].
<br>
<br> \ D Matches a non-numeric characters. Equivalent to [^ 0-9].
<br>
<br> \ f Matches a form feed character. Equivalent to \ x0c and \ cL.
<br>
<br> \ n matches a newline. Equivalent to \ x0a and \ cJ.
<br>
<br> \ r matches a carriage return. Equivalent to \ x0d and \ cM.
<br>
<br> \ s match any whitespace characters, including spaces, tabs, page breaks and so on. Equivalent to [\ f \ n \ r \ t \ v].
<br>
<br> \ S Matches any non whitespace character. Equivalent to [^ \ f \ n \ r \ t \ v].
<br>
<br> \ t Matches a tab character. Equivalent to \ x09 and \ cI.
<br>
<br> \ v Matches a vertical tab. Equivalent to \ x0b and \ cK.
<br>
<br> \ w matches any word character including underscore. Equivalent to '[A-Za-z0-9_]'.
<br>
<br> \ W matches any non-word characters. Equivalent to '[^ A-Za-z0-9_]'.
<br>
<br> \ xn match n, where n is a hexadecimal escape value. Hexadecimal escape values must be determined by two digits long. For example, '\ x41' matches "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. Match obtained on a reference. For example ,'(.) \ 1 'matches two consecutive identical characters.
<br>
<br> \ n identifies an octal escape value or a back reference. If the \ n before the acquisition at least one sub-expression n, then n is after the reference. Otherwise, if n is an octal digit (0-7), then n is an octal escape value.
<br>
<br> \ nm identifies an octal escape value or a back reference. If \ nm until at least is preceded by at least nm were obtained was sub-expression, then the nm to the reference for the post. If \ nm at least n months before the acquisition, followed by the text is n m for a backward reference. If the preceding conditions are not met, if n and m are octal digits (0-7), then \ nm matches octal escape value nm.
<br>
<br> \ nml If n is an octal digit (0-3), and m and l are octal digits (0-7), then match the octal escape value nml.
<br>
<br> \ un match n, where n is a four hexadecimal digits with the Unicode characters. For example, \ u00A9 matches the copyright symbol (?).
<br>
<br>
<br> <span> order of priority </ span>
<br> in constructing regular expressions, you can find as to the value of the same mathematical expression, that is, from left to right and in accordance with a priority order to find value.
<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 character
(), (?:), (?=), [] 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 the character of the print and non print characters. This includes all uppercase and lowercase characters, all numbers, all punctuation marks and some symbols.
<br>
<br> 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' to match the search string appear anywhere in the letter 'A'. Here are some single-character regular expression pattern example:
<br> <pre name="code"> / a /
/ 7 /
/ M /
</ Pre>
<br> VBScript equivalent single character regular expression is:
<br> <pre name="code"> "a"
"7"
"M"
</ Pre>
<br> can combine multiple single character to get a larger expression. For example, the following JScript regular expression is nothing but an expression by combining single characters' 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>

相关文章
  • Regular Expression Reference 2010-11-08

    / / 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 ,"_","." Java

  • 12. Regular Expression: Reverse Reference 2010-03-17

    Regular expression is one of the most important function of the pattern matching part of storage for later re-use capabilities. You may think that if the regular expression pattern or pattern part with brackets on both sides will lead to a part of th

  • grep regular expression used in reference 2010-11-03

    grep regular expression meta-character set: ^ Start of line anchor, such as: '^ grep' matches all lines that begin with grep. $ Anchor end of the line such as: 'grep $' matches the end of the line for all to grep. The matching of a non-newline charac

  • Regular expression based on JS 2009-08-06

    Character / Significance: For the characters, usually expressed by the literal meaning, pointing out that the next character for special characters, does not explain. For example: / b / matches the characters' b ', preceded by a backslash b, that is,

  • 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

  • Java regular expression explanation 2010-03-29

    Java regular expression explanation expression meaning: 1. Character x character x. For example, a character that a \ \ Backslash character. In the writing time to write to \ \ \ \. (Note: Because java in the first analysis, they can put \ \ \ \ pars

  • JS regular expression (3) 2010-02-06

    Border and non-boundary \ b expressed in the meaning of the border, that is, only the string at the beginning and end of the count. For example, / \ bc / beginning of the string on that end of the c or c. See the following example: <script type="t

  • JS regular expression (5) 2008-06-23

    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: <script type="text/javascript"&

  • 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

  • 2. Regular Expression: Regular Expression Syntax 2010-03-17

    Regular expression is a text mode, including ordinary characters (for example, a to z between the letters) and special characters (called "meta characters"). Model described in the search text to match one or more strings. Here are some examples

  • 6. Regular expression: special characters 2010-03-17

    Many meta-character requirement when they are trying to match the special treatment. To match the special characters, you must first make the character "escape", that is, the backslash character (\) placed in front of them. The following table l

  • 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

  • Regular expression summary 2010-03-02

    1. \ Bhi \ b that word hi, where \ b is a word separator 4 ..* that does not contain any newline characters 5. Newline character '\ n', asiic to 10,0 x0A 6. China phone number format: 0 \ d \ d-\ d \ d \ d \ d \ d \ d \ d \ d (to 0, the two figures,

  • Regular expression related 2010-02-25

    Transfer from Visual Studio Development Center http://msdn.microsoft.com/zh-cn/library/28hw3sce% 28VS.80% 29.aspx Regular Expressions Introduction <!----> <! - Content type: DocStudio. Transform: devdiv2mtps.xslt .--> These chapters introduce

  • js regular expression 2010-03-26

    follow. For example to match all but a or b of the characters, character classes can write [^ ab] ^ Locator provides matching pattern must be present in the target string at the beginning of it mean that ^ in [] which says that exclude (negative clas

  • Regular expression from the foundation to learn the 2010-03-21

    [Edit this paragraph] 1, what is the regular expression a regular expression is a pattern to match with a string of a formula for a class. Many more people because they look so strange and complex not to use - unfortunately, this article will not be

  • Regular expression syntax 2010-04-01

    A regular expression is the general character (such as characters a to z) and special characters (called metacharacters) composed of text mode. The model describes the main characters in the search to be matched when one or more strings. Regular expr

  • 30 minutes of the regular expression tutorial 2010-04-08

    Transfer from: http://deerchao.net/tutorials/regex/regex.htm This goal Regular expressions in the end is what? Computer software for word processing characters are the basic unit of time may be letters, numbers, punctuation, spaces, line breaks, char

  • All of the summary - the regular expression 2010-04-11

    [java regular expression used is not tested - escape some problem] 2008-12-26 15:56 "^ \ D + $" / / non-negative integers (positive integer + 0) "^ \ [0-9 \] * \ [1-9 \] \ [0-9 \] * $" / / a positive integer "^((- \ \ D +) | (0 +)

  • Java regular expression in a variety of characters, and an explanation of escaped characters 2010-04-11

    1. Character x character x. For example, a character that a \ \ Backslash character. In writing when the write to \ \ \ \. (Note: because java when the first resolution, to \ \ \ \ parsing into the regular expression \ \, again when the second resolu