Regular expression Formula Regular expression learning tool _ regular expression

Source: Internet
Author: User
Tags control characters numeric value pow rar
Signed on the Internet too much of the introduction is a fierce essay, while looking at the understanding can help memory not. Also by Wubi font root table formula "managed to watch 32 Jin ..." Inspiration,
Try "Regular Expression mnemonics" also known as "regular Limerick", version 0.1, absolutely original, counterfeit must investigate,:
Note: This article is only for the study of the regular time in order to facilitate memory, can not replace the system and comprehensive learning process, errors and omissions, please correct me!
Is in fact also snobbish, cutting the point to put the money; (refers to the start symbol ^ and the end sign $)
Special symbols can not recognize, get a backward bar to guide; \* and other special symbols)
Behind the back with the small W, the number of letters to express; (\w with digital letters; \d with numbers)
The back of the bar with small d, only numbers to indicate;
Behind the bar with small a, alarm symbol beep;
Behind the bar with small B, word demarcation or backspace;
Behind the back with small t, the tab symbol is very clear;
The back of the bar with small r, carriage return symbol to know;
Behind the bar with small s, the space symbol is very important;
Lower case with the upper case, too much is really not;
Behind the back with the Big W, the letter number aside;
Behind the bar with big S, blank also on the sidelines;
Behind the bar with Big D, the number from the sidelines;
The back of the box with Big B, does not include the beginning and end;

Single character to repeat, three symbols to help; )
0 Stars plus 1 to infinity, the question mark only 0 and 1; (* table 0-n;+ table 1-n;? Table 0-1 repeats)
More knowledge in curly braces, strong repetitive operation; ({n} {n} {n,m})
To repeat the string, enclose it in the garden; ((ABC) {3} indicates that the string "abc" Repeats 3 times)
Special set customization, brackets to help you;
Escape symbol not workable, one to line up;
There are so many of them out of line, please come and help me. ([1-5])
A sharp point is placed in brackets, and the definition of antisense is powerful; ([^a] refers to any character other than "a")
1 vertical function is not small, the two sides are replacing each other; (the keyboard is the same key as "\")
1 vertical energy used many times, complex definition is very convenient;
Garden brackets, multi-purpose;
A reverse reference to the specified group, with numeric rows corresponding to it; (The number "1" in "\b (\w+) \b\s+\1\b" refers to the preceding "(\w+)")
Support Group name customization, question mark with angle bracket, ("(? <word>\w+)" "\w+" defined as group, group named "Word")
The square bracket, uses many, the position designation depends on it;
Question mark equals string, positioned before the string ("\b\w+ (? =ing\b)" Locates the string before "ing")
To locate a string, insert a less than sign in the middle, ("(? <=\bsub) \w+\b" to the string following the "sub")
The question mark adds an exclamation point, followed by a string of strings;
Phper all know,! is to take the opposite meaning;
Back not with this string, all meet to report; ("\w*d!" OG) \w* "," dog "does not meet," do "in accordance with"
The question mark is less than the exclamation point followed by string strings;
The front does not put this string, all conforms to report;
Dot asterisk is greedy, add a question mark not greedy;
The plus question mark has the guarantee, at least repeat more than once;
Two question mark old rules, 0 times 1 times round;
Curly braces followed by a? , greed becomes not greedy;
There are a lot of not fit, waiting to be added later.
--------------------------------------------------------------------------------


Some common regular expressions

"^\d+$"//non-negative Integer (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+)? $"//nonnegative floating-point number (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]*)] $ "//Positive floating-point number
"^ ((-\d+ (\.\d+)?) | (0+ (\.0+)) $ "//non-positive floating-point number (negative floating-point number + 0)
^ (-([0-9]+\. [0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*\. [0-9]+) | ([0-9]*[1-9][0-9]*))] $ "//negative floating-point number
"^ (-?\d+) (\.\d+)? $"//floating-point number
"^[a-za-z]+$"//A string of 26 English letters
"^[a-z]+$"//A string of 26 uppercase letters
"^[a-z]+$"///a string consisting of 26 lowercase letters
"^[a-za-z0-9]+$"//A string of numbers and 26 English letters
"^\w+$"//A string of numbers, 26 English letters, or underscores
"^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$ "//email address
"^[a-za-z]+://(\w+ (-\w+) *) (\. ( \w+ (-\w+) *)) * (\?\s*) $ "//url
/^ (D{2}|d{4})-((0 ([1-9]{1})) | ( 1[1|2])-(([0-2] ([1-9]{1})) | ( 3[0|1]) $///year-month-day
/^ ((0 ([1-9]{1})) | (1[1|2]) /(([0-2] ([1-9]{1})] | (3[0|1]) /(D{2}|d{4}) $///month/day/year
"^ ([w.] +) @ ([[0-9]{1,3}. [0-9] {1,3}. [0-9] {1,3}.) | (([w-]+.) +)) ([a-za-z]{2,4}| [0-9] {1,3}) (]?) $ "//emil
"(d+-)?" (d{4}-?d{7}|d{3}-?d{8}|^d{7,8}) (-d+)? " Phone number
"^ (d{1,2}|1dd|2[0-4]d|25[0-5]). (D{1,2}|1dd|2[0-4]d|25[0-5]). (D{1,2}|1dd|2[0-4]d|25[0-5]). (D{1,2}|1dd|2[0-4]d|25[0-5]) $ "//IP address



Matching regular expressions for Chinese characters: [\U4E00-\U9FA5]
Match Double-byte characters (including Chinese characters): [^\x00-\xff]
A regular expression that matches a blank row: \n[\s|] *\r
Regular expression matching HTML tags:/< (. *) >.*<\/\1>|< (. *) \/>/
Matching a regular expression with a trailing space: (^\s*) | (\s*$)
Regular expression matching an email address: \w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *
A regular expression that matches URL URLs: ^[a-za-z]+://(\\w+ (-\\w+) *) (\ \\w+ (-\\w+) *)) * (\\?\\s*)? $
Match account number is legal (beginning of letter, allow 5-16 bytes, allow alphanumeric underline): ^[a-za-z][a-za-z0-9_]{4,15}$
Match domestic phone number: (\d{3}-|\d{4}-)? (\d{8}|\d{7})?
Matching Tencent QQ Number: ^[1-9]*[1-9][0-9]*$

The following table is a complete list of metacharacters and its behavior in the context of regular expressions:

\ marks the next character as a special character, or a literal character, or a back reference, or a octal escape character.

^ matches the start position of the input string. If the multiline property of the RegExp object is set, ^ also matches the position after ' \ n ' or ' \ R '.

$ matches the end position of the input string. If the multiline property of the RegExp object is set, the $ also matches the position before ' \ n ' or ' \ R '.

* Match the preceding subexpression 0 or more times.

+ matches the preceding subexpression one or more times. + is equivalent to {1,}.

? Match the preceding subexpression 0 times or once.? is equivalent to {0,1}.

{n} n is a non-negative integer that matches the determined N times.

{N,} n is a non-negative integer that matches at least n times.

{n,m} m and n are non-negative integers, where n <= m. Matches n times at least and matches up to M times. You cannot have spaces between commas and two numbers.

? When the character is immediately following any of the other qualifiers (*, +,?, {n}, {n,}, {n,m}), the matching pattern is not greedy. Non-greedy patterns match as few strings as possible, while the default greedy pattern matches as many of the searched strings as possible.

. Matches any single character except "\ n". To match any character including ' \ n ', use a pattern like ' [. \ n] '.
(pattern) matches the pattern and gets the match.

(?:p Attern) matches pattern but does not get matching results, which means that this is a non fetch match and is not stored for later use.

(? =pattern) forward lookup, matching the find string at the beginning of any string matching pattern. This is a non-fetch match, that is, the match does not need to be acquired for later use.

(?! pattern) Negative forward check, contrary to (? =pattern) Effect

X|y matches x or Y.

[XYZ] Character set combination.

[^XYZ] Negative character set combination.

[A-z] character range that matches any character within the specified range.

[^a-z] A negative character range that matches any character that is not in the specified range.

\b Matches a word boundary, which refers to the position between the word and the space.

\b Matches a non word boundary.

\CX matches the control characters indicated by X.

\d matches a numeric character. equivalent to [0-9].

\d matches a non-numeric character. equivalent to [^0-9].

\f matches a page feed character. Equivalent to \x0c and \CL.

\ n matches a newline character. Equivalent to \x0a and \CJ.

\ r matches a carriage return character. Equivalent to \x0d and \cm.

\s matches any white space character, including spaces, tabs, page breaks, and so on. equivalent to [\f\n\r\t\v].

\s matches any non-white-space character. equivalent to [^ \f\n\r\t\v].

\ t matches a tab character. Equivalent to \x09 and \ci.

\v matches a vertical tab. Equivalent to \x0b and \ck.

\w matches any word character that includes an underscore. Equivalent to ' [a-za-z0-9_] '.

\w matches any non word character. Equivalent to ' [^a-za-z0-9_] '.

\XN matches N, where n is the hexadecimal escape value. The hexadecimal escape value must be a determined two digits long.

\num matches num, where num is a positive integer. A reference to the match that was obtained.

\ n identifies a octal escape value or a back reference. N is a back reference if you have at least N obtained subexpression before. Otherwise, if n is an octal number (0-7), then N is an octal escape value.

\NM identifies a octal escape value or a back reference. NM is a \nm if at least one of the preceded by the at least NM gets the subexpression before the If there are at least N fetches before \nm, then N is a back reference followed by a literal m. If all the preceding conditions are not satisfied, if both N and M are octal digits (0-7), then \nm will match octal escape value nm.

\NML if n is an octal number (0-3) and both M and L are octal digits (0-7), then the octal escape value NML is matched.

\un matches N, where N is a Unicode character represented in four hexadecimal digits.

Matching regular expressions for Chinese characters: [U4E00-U9FA5]

Match Double-byte characters (including Chinese characters): [^x00-xff]

Application: Computes the length of the string (a double-byte character length meter 2,ascii character 1)

String.prototype.len=function () {return This.replace ([^x00-xff]/g, "AA"). Length;}

A regular expression that matches a blank row: n[s|] *r

Regular expression matching HTML tags:/< (. *) >.*</1>|< (. *)/>/

Matching a regular expression with a trailing space: (^s*) | (s*$)

Application: JavaScript does not have a trim function like VBScript, we can use this expression to implement, as follows:

String.prototype.trim = function ()
{
Return This.replace (/(^s*) | ( s*$)/g, "");
}

To decompose and transform an IP address using a regular expression:

The following is a JavaScript program that uses a regular expression to match an IP address and converts an IP address to a corresponding numeric value:

function IP2V (IP)
{
re=/(d+). (d+). (d+). (d+)/g//matching the regular expression of the IP address
if (Re.test (IP))
{
Return Regexp.$1*math.pow (255,3)) +regexp.$2*math.pow (255,2)) +regexp.$3*255+regexp.$4*1
}
Else
{
throw new Error ("not a valid IP address!")
}
}

However, if the above program does not use a regular expression, and the split function directly to decompose may be simpler, the program is as follows:

var ip= "10.100.20.168"
Ip=ip.split (".")
Alert ("IP value is:" + (IP[0]*255*255*255+IP[1]*255*255+IP[2]*255+IP[3]*1))

Regular expression matching an email address: w+ ([-+.] w+) *@w+ ([-.] w+) *.w+ ([-.] w+) *

A regular expression that matches URL URLs: http://([w-]+.) +[w-]+ (/[w-/?%&=]*)?

An algorithmic program that uses regular expressions to remove repetitive characters from a string:

var s= "Abacabefgeeii"
var s1=s.replace (/(.). *1/g, "$")
var re=new RegExp ("[" +s1+ "]", "G")
var s2=s.replace (Re, "")
Alert (S1+S2)//Result: ABCEFGI

You have to use regular expressions to extract the filename from the URL address of the JavaScript program, the following result is Page1

S= "Http://www.9499.net/page1.htm"
S=s.replace (/. * *) {0,} ([^.] +). */ig, "$"
Alert (s)

Use regular expressions to restrict the entry of text boxes in a Web page's form:

The regular expression limit can only be entered in Chinese: onkeyup= "value=value.replace (/[^u4e00-u9fa5]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^u4e00-u9fa5]/g, ') "

Only full-width characters can be entered with regular expression restrictions: onkeyup= "Value=value.replace (/[^uff00-uffff]/g,") "Onbeforepaste=" Clipboarddata.setdata (' Text ', Clipboarddata.getdata (' text '). Replace (/[^uff00-uffff]/g, ') "

Only numbers can be entered with regular expression restrictions: onkeyup= "Value=value.replace (/[^d]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^d]/g, ') "

Only numbers and English can be entered with regular expression restrictions: onkeyup= "Value=value.replace (/[w]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^d]/g, ') "

Regexp.zip

Rexlist+regex processing Tool +v2[1].0+ Green official version. rar
Regex test Tool +1[1].0+regextester.rar

Regex tool +mtracer+2[1].0.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.