[Reprint] regular expression

2010-07-27  来源:本站原创  分类:Web  人气:264 

Reprint address http://www.javaeye.com/topic/719950

Regular Expressions
/ / Check if 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 months beginning with the letter can be a string with digital ,"_","."

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: Enter only 1-30 months beginning with the letter string

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. Under the plan
function isPasswd(s)
{
var patrn=/^(\w){6,20}$/;
if (!patrn.exec(s)) return false
return true
}
//  Check ordinary telephone. Fax Number  :  Can "+" at the beginning  ,  In addition to numbers, may contain  "-"
function isTel(s)
{
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false
return true
}
//  Check phone number  :  Must begin with a number, in addition to numbers  ,  May contain  "-"
function isMobil(s)
{
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false
return true
}
//  Check Postal Code
function isPostalCode(s)
{
var patrn=/^[a-zA-Z0-9 ]{3,12}$/;
if (!patrn.exec(s)) return false
return true
}
//  Check the search keyword
function isSearch(s)
{
var patrn=/^[^`[email protected]#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`[email protected]$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/;
if (!patrn.exec(s)) return false
return true
}
function isIP(s)
{
var patrn=/^[0-9.]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
  Regular Expressions
"^\\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_]*$"

Regular expressions uses Xiangjie Introduction simply, is a regular expression pattern matching and can be used to replace a powerful tool. Its role as follows:
Test string to a pattern. For example, an input string can be tested to see whether the string model there is a phone number or a credit card number pattern. This is called data validation.
Replacement text. May in the document using a regular expression to identify a specific text, then you can all be deleted, or replaced with other text.
According to pattern matching to extract from the string of a substring. Can be used in the text or to find specific text entry field.

Basic syntax of the regular expressions in the function and role of the initial understanding, we look on to the specific regular expression syntax.
The general form of regular expressions as follows:
/ Love / which is located in "/" delimiter is the part between the target object to be matched in the pattern. Users want to find as long as the content matches the object model into the "/" between the delimiter can be. In order to allow users to customize the model more flexible content, regular expressions provide a special "metacharacters."

The so-called meta-character means that the regular expression special characters with special meaning, can be used to specify the leading characters (or in front of the character per character) appears in the target object model.

The more commonly used meta-characters: "+", "*", and "?."

"+" Metacharacter provides its leading characters must appear in the target one or more times in a row.
"*" Metacharacter provides its leading characters must appear in the target object or a continuous number zero.
"?" Per the provisions of its leading characters in the target object, the object must be consecutive zero or one.
Now, let us look at regular expression metacharacters specific application.
/ Fo + / because the regular expression contains "+" meta characters that can target the "fool", "fo", or "football" so the letter f in the back of one or more consecutive characters in the letter o string matching.
/ Eg * / because the regular expression contains "*" meta characters that can target the "easy", "ego", or "egg" so the letter e in the back of zero or more consecutive letters g string match.
/ Wil? / Because the regular expression contains a "?" Meta characters that can target the "Win", or "Wilson", such as the letter i in the back of consecutive zero or a letter l of the strings match.
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 regular expressions for a given number of components have to be there to meet the match.
(N) n is a non-negative integers. Matching of the n times. For example, 'o (2)' can not match the "Bob" in the 'o', but can match the "food" in the two o.
(N,) n is a non-negative integers. Match at least n times. For example, 'o (2,)' can 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 *'.
(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?'. Please note that the comma and no space between the two numbers.
In addition to metacharacters, the user can precisely specify the pattern matching object in the frequency.

For example, / jim (2,6) / the provisions of the regular expression characters that can match object m consecutive 2-6 times, therefore, the regular expression so you can string with jimmy or jimmmmmy match.
On how to use regular expressions have a preliminary understanding, we look at several other important meta-characters used.
\ 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 numbers 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.
(Note: we can \ s and \ S and \ w and \ W as mutually inverse)

Here, we look through the examples of how to use the regular expression metacharacters.
\ S + / The regular expression can be used to match the target object in one or more space characters.
\ D000 / If we have in hand a complex financial statements, we can easily above the regular expression to find all the money amounted to 1,000 yuan.
In addition to our meta-characters described above, the regular expression in a more unique and also has another special character, that website. Locator provides matching pattern for the target object appears in the position. The more commonly used website include: "^", "$", "\ b" and "\ B".
"^" Matches the pattern Locator provisions must appear in the target string at the beginning of "$" match the pattern Locator provides the target object must appear at the end of "\ b" matches the pattern Locator provisions must appear in the target string at the beginning or end of one of the two border "\ B" website provides an object must match the target string at the beginning and end of the two boundaries within
That the object can not match the target string at the beginning, not as a target end of the string.

Similarly, we can also "^" and "$" and "\ b" and "\ B" as the two mutually inverse website. For example:

/ ^ Hell / because the regular expression contains "^" website, so can the target object to "hell", "hello" or "hellhound" at the beginning of the string to match.

/ Ar $ / because the regular expression contains "$" website, so can the target object to "car", "bar" or "ar" at the end of the string to match.

\ Bbom / because the regular expression pattern with "\ b" website at the beginning, it can be the target object to "bomb", or "bom" at the beginning of the string to match.

/ Man \ b / because the regular expression pattern with "\ b" website at the end, it can be the target object to "human", "woman" or "man" at the end of the string to match.
To be able to set more flexible user-friendly match mode, the regular expression pattern matching allows users to specify a range rather than a

Limited to specific characters. For example: / [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 lower case letters to match any.
/ [0-9] / the regular expression will work with the range from 0 to 9 to match any of a 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.

It should be noted that point is to remind the user 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" string match such as "abc" in the last character for the letters instead of numbers.

If we want to achieve in the regular expression in a similar programming logic "or" operation, in a number of different modes to choose one match, then you can use the pipe symbol "|".

For example: / to | too | 2 / the regular expression will be the target object "to", "too", or "2" to match.
Regular expressions are a more commonly used operators, that the negative character "[^]". With our previously described Locator "^" different,
Provisions of the negative character "[^]" target object model can not exist under the string.

For example: / [^ AC] / the string will be the target object, in addition to A, B, and C matches any character other than. Generally speaking, when the "^" in "[]" in the negative when it is viewed as the operator; and when the "^" in "[]" other than, or not "[]", then should be viewed as Locator.
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 *" and not "The" other match.

In constructing regular expressions, you can come to seek the same as the value of mathematical expression, that is, from left to right and in accordance with a priority order of evaluation.

Priority is as follows:
1. \ Escape character
2. (), (?:), (?=), [], Parentheses and brackets
3. *, +,?, (N), (n,), (n, m) qualifier
4. ^, $, \ Anymetacharacter location and sequence
5. | "Or" operation

Use examples in JavaScript 1.2 in with a powerful RegExp () object, 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.
We can write the following script using JavaScript to verify user input validity of email addresses.

<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>

Regular Expression object this object contains the regular expression patterns and show how to apply the model sign.
Syntax 1 re = / pattern / [flags]
Syntax 2 re = new RegExp ("pattern", ["flags"])

Parameter
re Required. Will be assigned to a regular expression pattern of the variable name.
Pattern 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.
Flags Optional. If you use Syntax 2, use quotation marks to flag cause to. Flag can be used in combination, can be used are:
g (full text search appears all the pattern)
i (ignore case)
m (multi-line search)

Example

The following example creates a regular expression object model and associated logo (re), to show you the usage of regular expression objects. In this case, as a result of the regular expression object to match another method:

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);
}

Return Value: ain, ain, ain, ain
exec method pattern using regular expressions to run in the string to find, and returns an array of the search results.
rgExp.exec (str)
Parameter

rgExp Required. Contains the regular expression pattern and the available regular expression object symbol.
str Required. In which the implementation of the String object or string to find the text.
Note 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. 0 array element contains a complete match, and 1 to n elements is contained in matching a child appearing in any match. This is equivalent to not set the global flag (g) The match method.
If the regular expression to set the global flag, exec instructions from a position of the value of lastIndex start search. If not set the global flags, exec ignored lastIndex value, the starting position from the start the search string.
exec method returns an array with three attributes, namely input, index and lastIndex. Input attribute contains the entire search string is.

Index property contains the search string to be matched by the sub-string position.

LastIndex property contains the last match of the next character position.

Example The following example illustrates the use of exec method:

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  ");
}
}

Return Value :0-3The 4-8rain 9-11in 12-17Spain 18-23falls 24-30mainly 31-33in 34-37the38-43plain
test method returns a Boolean value, it pointed out that the string was to find whether there are patterns.
rgexp.test (str) Parameters
rgexp Required. Contains the regular expression pattern or regular expression can mark an object.
str Required. To test the look in his string.
Explain
test method checks whether the string there is a pattern, if it returns true, otherwise returns false.
Global RegExp object's properties not help to modify the test method.
Example The following example illustrates the use of test methods:

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  .
}

Function call: document.write (TestDemo (/ ain + /, "The rain in Spain falls mainly in theplain ."));
Return Value: 'The rain in Spain falls mainly in the plain.' Contains 'ain +'
method uses a regular expression match patterns on the implementation of search strings, and contains the search results as an array to return. \ \
stringObj.match (rgExp) parameters
stringObj Required. String to search for its object or text string.
rgExp Required. To contain the regular expression pattern and the available regular expression object symbol. Can also be included regular expression pattern and the available marks text variable name or string.
Note If the match is not found matching method, return null. If a match is found returns an array and update the global RegExp object's properties to reflect the matching results.
match method returns the array has three attributes: input, index and lastIndex.

Input attribute contains the entire search string is.

Index property contains the search string in the whole match was sub-string position.

LastIndex attribute contains the last match of the last character of the next position.
If not set the global flag (g), an array of 0 elements include the entire match, and 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 the global flag, elements 0 to n is included in all matches.
Example The following example demonstrates the use of match method:

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  .
}

Return Value: ain

This example illustrates the match with g flag set method of use.

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  .
}

Return Value: ain, ain, ain, ain
The above few lines of code demonstrate ways match the text string usage.

var r, re = "Spain";
r = "The rain in Spain".replace(re, "Canada");
return r;

Return Value: The rain in Canada
search method returns the contents of the regular expression match to find the location of the first sub-string.
stringObj.search (rgExp) parameters
stringObj Required. Carried out in the String object or string search text.
rgExp Required. Contains the regular expression pattern and the available regular expression object symbol.
Explain
search methods specify whether there is a corresponding match. If a match is found, search method returns an integer value, indicating the beginning of the string match from the offset location. If no match is found, it returns -1.

Example The following example demonstrates the use of search methods.

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  .
}

Return Value: 18

Regular expression syntax of a regular expression is by ordinary characters (for example, a character 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 Expressions as a template, the model and the search for a character string to match.
Here are some you may experience the regular expression examples:

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  Bit
  Numbers  .
/<(.*)>.*<\/\1>/ "<(.*)>.*<\/\1>"   Matches a HTML tag  .

The following table is the element in the regular expression characters and their behavior in the context of a complete list:
Character Description
\ Will be the next character is marked as a special character, or a literal character, or a backward reference, or an octal escape.

For example, 'n' match the character "n". '\ N' matches a newline character.

Sequence '\ \' matches "\" and "\ (" the match "(."
^ Matches the beginning of the string.

If you set the RegExp object's Multiline property, ^ also matches the '\ n' or '\ r' after the location.
$ Matches the end of the string position.

If you set the RegExp object's Multiline property, $ also matches the '\ n' or '\ r' before position.
* Matches the preceding subexpression zero or more times. For example, zo * to match the "z" and "zoo". * Is equivalent to (0).
+ Matches the preceding subexpression one or more times. For example, 'zo +' will match "zo" and "zoo", but can not match the "z". + Is equivalent to (1,).
? Match the previous sub-expression zero or one. For example, "do (es)?" Matches "do" or "does" in the "do". ? Is equivalent to (0,1).
(N) n is a non-negative integers. Matching of the n times. For example, 'o (2)' can not match the "Bob" in the 'o', but can match the "food" in the two o.
(N,) n is a non-negative integers. Match at least n times. For example, 'o (2,)' can 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 *'.
(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?'. Please note that the comma and no space between the two numbers.
? When the characters followed in any other qualifier (*, +,?, (N), (n,), (n, m)) behind, the non-greedy matching pattern.

Non-greedy pattern matches as little as possible the search string, and the default greedy pattern matches as much as possible the search string.
For example, the string "oooo", 'o +?' Will match a single "o", while 'o +' matches all 'o'.
. Matching except "\ n" beyond any single character. To match, including '\ n', including any characters, please use as '[. \ N]' model.
(Pattern) matches the pattern and get the match. Match can be obtained from the resulting Matches collection are, in
VBScript using SubMatches collection is used in the JScript in $ 0 ... $ 9 properties. To match parentheses characters, use '\ (' or '\)'.
(?: Pattern) matches the pattern but do not get matching results, 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 expressions.
(? = Pattern) Positive pre-investigation, in any matching string pattern matching to find the beginning of the 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)' to match
"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 containing pre-check of the character after the start.

(?! Pattern) negative pre-investigation, in any match Negative lookahead matches the search string atany point where a string not matching pattern matches the search string at the beginning of the 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)' to match the "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, not including pre-check of characters from the start after x | y matches x or y. For example, 'z | food' to match the "z" or "food". '(Z | f) ood' the match "zood" or "food".
[Xyz] character set. Matching contains any one character. For example, '[abc]' matches "plain" in the 'a'.
[^ Xyz] negative character set. Matches any character not included. For example, '[^ abc]' matches "plain" in the 'p'.
[Az] character range. Matches any character within the specified range. For example, '[az]' will match 'a' to 'z' within the scope of any lowercase alphabetic characters.
[^ Az] range of negative characters. 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.
\ B Match a word boundary, that is, that space between words and the location. For example, 'er \ b' matches "never" in the 'er', but can not match the "verb" in the 'er'.
\ B matches non-word boundary. 'Er \ B' to match the "verb" in the 'er', but can not match "never" in the 'er'.
\ Cx matches the control specified by the x character. For example, \ cM matches a Control-M or carriage return. x value must be one of AZ or az. Otherwise, c as a literal 'c' character.
\ D matches a digit character. Is equivalent to [0-9].
\ D matches a non-digit character. Is equivalent to [^ 0-9].
\ F matches a form feed character. Is equivalent to \ x0c and \ cL.
\ N matches a newline. Is equivalent to \ x0a and \ cJ.
\ R matches a carriage return. Is equivalent to \ x0d and \ cM.
\ S Matches any whitespace characters, including spaces, tabs, page breaks, etc. change. Is equivalent to [\ f \ n \ r \ t \ v].

\ S Matches any non-blank character. Is equivalent to [^ \ f \ n \ r \ t \ v].
\ T matches a tab character. Is equivalent to \ x09 and \ cI.
\ V matches a vertical tab. Is equivalent to \ x0b and \ cK.
\ W matches any word character including underscore. Is equivalent to '[A-Za-z0-9_]'.
\ W matches any non word character. Is equivalent to '[^ A-Za-z0-9_]'.
\ Xn match n, where n is a hexadecimal escape value. Hexadecimal escape values must be determined by two numbers long. For example, '\ x41'
Match "A". '\ X041' is equivalent to '\ x04' & "1". Regular expressions can be used in ASCII encoding. .
\ Num match num, where num is a positive integer. Get on the matching references. For example ,'(.) \ 1 'matches two consecutive identical characters.
\ N identifies an octal escape value or a backward reference. If the \ n at least n months to obtain prior to the sub-expression, then the n after the reference to. Otherwise, if n is an octal digit (0-7), then n is an octal escape value.
\ Nm marking an octal escape value or a backward reference. If \ nm until at least is preceded by at least nm were obtained for sub-expression, then the nm to the reference for the post. If \ nm at least n months before the acquisition, then n a m, followed by the text after the references. If the preceding conditions are not met, if n and m are octal digits (0-7), then \ nm matches octal escape value nm.
\ 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.
\ Un match n, where n is a hexadecimal digits in four of Unicode characters. For example, \ u00A9 matches the copyright symbol (?).
Order of priority

In constructing regular expressions, you can come to seek the same as the value of mathematical expression, that is, from left to right and in accordance with a priority order of evaluation.
The following table from the highest priority to lowest priority listed in the various regular expression operators in order of priority:
Operator Description
\ Escape character
(), (?:), (?=), [], Parentheses and brackets
*, +,?, (N), (n,), (n, m) qualifier
^, $, \ Anymetacharacter location and sequence
| "Or" operation

General character of ordinary character of all those who have not explicitly specified as per print and non-printing characters characters. This includes all uppercase and lowercase characters, all numbers, all punctuation and symbols.
The simplest regular expression is a single common character, 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 example:
/ A /
/ 7 /
/ M /
Single-character equivalent of the VBScript regular expression is:
"A"
"7"
"M"

You can combine multiple single character to get a larger expression. For example, the following JScript regular expression is nothing but a single character through a combination of expression 'a', '7 'and' M 'created out of an expression.
/ A7M / VBScript equivalent expression is: "a7M"
Please note that there are no connections operator. Need to do is a character on the back of another character.

相关文章
  • [Reprint] regular expression 2010-07-27

    Reprint address http://www.javaeye.com/topic/719950 Regular Expressions / / Check if 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 month

  • Common digital validation regular expression processing (reprint) 2010-12-03

    Transfer from: http://kingoa.net/WEBPROGRAM/REGEXP/2010/0909/21023.html Common digital finishing the regular expression validation, the development of friends often use to. Recommend the next collection. Verify numbers: ^ [0-9] * $ Verify the number

  • Js regular expression reproduced 2010-11-24

    http://www.cnblogs.com/rubylouvre/archive/2010/03/09/1681222.html These are the original addresses, style, clear and beautiful. The following is a reprint of the content. javascript regular expression Online tutorial on regular expressions enough, bu

  • Greedy regular expression matching 2011-07-13

    Greedy regular expression matching 2009-07-05 09:26:03 Tags: sed regular shell greed awk Original works, for permission to reproduce, reprint, please be sure to hyperlink to the article indicating the original source , author information and this sta

  • ruby regular expression match but does not contain 2009-03-21

    There is a demand to resolve (sdbeis) To the string in brackets Can also be <html> ...</ html> The ordinary course of events should be used (?=\{)[^{}]* Or [^{}]*(?=\}) Or (?=\{)[^{}]*(?=\}) This in fact, match but not in the scope of the regu

  • 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,

  • Step-by-step learning Ruby (10): Ruby Regular Expression (Part Two) 2009-09-23

    The content of this article: Greedy and non-greedy quantifier quantifier Anchor That forward-looking Modifiers With the string is converted Regular expressions commonly used local First, the greedy and non-greedy quantifier quantifier Quantifier * (z

  • Step-by-step learning Ruby (9): Ruby Regular Expression (I) 2009-09-23

    Recommend a first-line Ruby regular expression editor http://www.rubular.com/ Ruby's regular expressions of "/ /" as the constructor. Expression of the target returns a RegExp. General rules: / a / matches the characters a. / \? / Matching speci

  • 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

  • Review the past to a new regular expression javascript 2009-11-12

    Review the past to a new regular expression javascript

  • 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

  • Java Regular Expression Application summary (change) 2010-03-29

    First, an overview of A regular expression is Java Dealing with strings, the text of the important tool. Java The processing of regular expressions in the following two two classes: java.util.regex.Matcher pattern class: used to indicate a compiled r

  • Java Regular Expression Application Summary 2010-03-29

    Java Regular Expression Application Summary First, an overview of Regular expressions are Java handling strings, the text of the important tool. Java on the handling of regular expressions in the following two two classes: java.util.regex.Matcher pat

  • Groovy regular expression usage - c processing strings 2010-03-29

    The use of Groovy's regular expression handling strings Keywords: groovy Commonly used regular expressions Symbolic meaning of the expression matching is equivalent to the number \ d [0-9] Non-numeric \ D [^ 0-9] word character \ w [a-zA-Z0-9] The no

  • Regular expression escape character (change) 2008-05-08

    Character Matching Grammar: \ d Matches a digit (0 ~ 9) '\ d' matches the 8, does not match the 12; \ D Matches a non-digital '\ D' matches c, does not match the 3; \ w matches any single character '\ w \ w' matches A3, does not match the @ 3; \ W Ma

  • JS regular expression (1) 2009-02-16

    Create a regular expression, there are two ways // The first kind var reg = /pattern/; // The second kind var reg = new RegExp('pattern'); Regular expression exec method of profile reg.exec(str); Str which you want to target the implementation of reg

  • JS regular expression (2) 2008-07-06

    2 Select one, regular expressions, or, "|" b | c said that the match b or c. For example: <script type="text/javascript"> function execReg(reg,str){ var result = reg.exec(str); alert(result); } reg = /b|c/; str='bbc'; execReg(reg

  • 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"&

  • Common JavaScript validation regular expression (change) 2009-01-30

    Chinese characters matching the regular expression: [u4e00-u9fa5] Comment: The match really is a headache for the Chinese thing, with this expression on the much easier to handle Matching double-byte characters (including the Chinese characters inclu