Regular expression Examples _ regular expressions

Source: Internet
Author: User
Example of regular expressions

The following table shows examples of the use of regular expressions. All of the examples apply to REGEXP, and some of the examples apply to the SIMILAR to, such as comments in the sample column. The results vary depending on the search criteria that you use for the search. For examples that use SIMILAR to, the results also vary depending on whether the case is case-sensitive or accented.

For a comparison of how REGEXP and SIMILAR to handle matching and calculation scopes, see like, REGEXP, and SIMILAR to search conditions.

Note that if you use these examples in a literal string (for example, '. +@.+\\. + '), you should use the double backslash example to match the sample credit card number (REGEXP only):

Visa:

4[0-9]{3}\S[0-9]{4}\S[0-9]{4}\S[0-9]{4}

MasterCard:

5[0-9]{3}\S[0-9]{4}\S[0-9]{4}\S[0-9]{4}

American Express:

37[0-9]{2}\S[0-9]{4}\S[0-9]{4}\S[0-9]{4}

Discover:

6011\S[0-9]{4}\S[0-9]{4}\S[0-9]{4}

Matching (Visa): 4123 6453 2222 1746

Non-match (Visa):

3124 5675 4400 4567, 4123-6453-2222-1746

Similarly, MasterCard matches a set of 16-bit numbers, starting with 5, each with a single space between the subsets of each four-digit number. American Express and Discover are the same, but must begin with 37 and 6011 respectively. Date (REGEXP and SIMILAR to are applicable):

([0-2][0-9]|30|31)/(0[1-9]|1[0-2])/[0-9]{4}

Match: 31/04/1999, 15/12/4567

Non-match: 31/4/1999, 31/4/99, 1999/04/19, 42/67/25456 Windows Absolute Path (REGEXP only):

([a-za-z]:|\\) \\[[:alnum:][:whitespace:]! " #$%& ' () +,-. \\;=@\[\]^_ ' {}~.] *

Match: \\server\share\file

Non-match: \directory\directory2,/directory2 e-mail address (REGEXP only):

[[: word:]\-.] +@[[:word:]\-.] +\. [[: Alpha:]] {2,3}

Match: abc.123@def456.com, _123@abc.ca

Non-match: Abc@dummy, ab*cd@efg.hijkl e-mail address (REGEXP only):

.+@.+\.. +

Match: * @qrstuv @wxyz.12345.com, __1234^%@ @abc. def.ghijkl

Non-match: Abc.123.*&ca, ^%abcdefg123 HTML hexadecimal color codes (REGEXP and SIMILAR to all apply):

[A-f0-9] {6}

Match: AB1234, CCCCCC, 12af3b

Non-match: 123g45, 12-44-cc HTML hexadecimal color code (REGEXP only):

[A-f0-9] {2}\s[a-f0-9]{2}\s[a-f0-9]{2}

Match: AB, CC D3

Non-match: SS AB CD, AA BB CC DD, 1223AB IP address (REGEXP only):

((2 (5[0-5]|[ 0-4][0-9]) |1 ([0-9][0-9]) | ([1-9][0-9]) | [0-9]) \.) {3} (2 (5[0-5]|[ 0-4][0-9]) |1 ([0-9][0-9]) | ([1-9][0-9]) | [0-9])

Match: 10.25.101.216

Non-match: 0.0.0, 256.89.457.02 Java annotations (REGEXP only):

/\*.*\*/|//[^\n]*

Matches a Java annotation between/* and */, or a line of comments prefixed with//.

Non-match: a=1 currency (REGEXP only):

(\+|-) \$[0-9]*\. [0-9] {2}

Match: $1.00,-$97.65

Mismatched: $, 1.00$, $-75.17 positive, negative, and decimal values (REGEXP only):

(\+|-)? [0-9]+ (\.[ 0-9]+)?

Match: +41,-412, 2, 7968412, 41, +41.1,-3.141592653

Non-matching: ++41, 41.1.19,-+97.14 password (REGEXP and SIMILAR to all apply):

[[: Alnum:]] {4,10}

Matching: ABCD, 1234, A1B2C3D4, 1A2B3

Non-match: ABC, *AB12, abcdefghijkl password (REGEXP only):

[a-za-z]\w{3,7}

Match: Ab_cd, A1_B2C3, a123_

Non-match: *&^g, ABC, 1BCD phone number (REGEXP and SIMILAR to all apply):

([2-9][0-9]{2}-[2-9][0-9]{2}-[0-9]{4}) | ([2-9][0-9]{2}\s[2-9][0-9]{2}\s[0-9]{4})

Matching: 519-883-6898, 519 888 6898

Non-match: 888 6898, 5198886898, 519 883-6898 sentences (REGEXP only):

[A-z0-9].* (\.| \?|!)

Match: Hello, how are you?

Non-match: I am fine sentence (REGEXP only):

[[: upper:]0-9].*[.?!]

Match: Hello, how are you?

Non-match: I am fine Social Security Number (REGEXP and SIMILAR to all apply):

[0-9] {3}-[0-9]{2}-[0-9]{4}

Match: 123-45-6789

Non-match: 123 6789, 123456789, 1234-56-7891 URL (REGEXP only):

(http://) www\. [A-za-z0-9]+\. [A-za-z] {2,3}

Matching: http://www.sample.com, www.sample.com

Non-match: http://sample.com, Http://www.sample.comm

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.