Characters, descriptions, and simple application examples of regular expressions.

Source: Internet
Author: User

Characters, descriptions, and simple application examples of regular expressions.

 

Characters and their meanings

Character meaning

\ Escape character, escape a character with special functions into a common character

^ Match the start position of the string

$ End position of matching string

* Match the previous zero or multiple subexpressions

+ Match the previous subexpression once or multiple times

? Match the subexpression of the previous zero multiple times

{N} n is a non-negative integer that matches the previous n subexpressions.

{N ,}n is a non-negative integer. It must match at least n subexpressions.

{N, m} m, n are all non-negative integers, where n <= m, matches at least n times and can match up to m times

? When following other delimiters (*, + ,?, {N}, {n ,},{ n, m}), the matching mode matches as few strings as possible.

. Match any single character except "\ n"

(Pattern) matches pattern and obtains this match.

(? : Pattern) matches pattern but does not get the matching result.

(? = Pattern) Forward pre-query, matching the search string at the beginning of any string that matches pattern

(?! Pattern) negative pre-query, matching the search string at the beginning of any string that does not match pattern

X | y matches x or y

[Xyz] match any character contained

[^ Xyz] match any character not included

[A-z] matches any character in the specified range

[^ A-z] match any character that is not within the specified range

\ B matches a word boundary, that is, the position between a word and a space.

\ B match non-word boundary

\ D matches a numeric character, which is equivalent to [0-9 ].

\ D matches a non-numeric character, which is equivalent to [^ 0-9]

\ F matches a newline

\ N matches a linefeed.

\ R matches a carriage return.

\ S matches any blank characters, including spaces, tabs, and page breaks.

\ S matches any non-blank characters

\ T matches a tab

\ V matches a vertical tab.

\ W matches any word characters that contain underscores. Equivalent to [a-zA-Z0-9 _]

\ W matches any non-word characters. Equivalent to [^ a-zA-Z0-9 _]

 

Use the regular exec Method for front-end js verification. The Code is as follows:

1 

 

The background uses regular expressions and the namespace using System. Text. RegularExpressions must be introduced. The static method IsMatch () of Regex is used. The Code is as follows:

1 protected void Button_Click (object sender, EventArgs e) 2 {3 string patten = @ "^ \ d {8} $"; 4 Regex regex = new Regex (patten ); 5 string text = TextBox1.Text. trim (); 6 if (! Regex. isMatch (text) 7 {8 ClientScript. registerStartupScript (ClientScript. getType (), "", "<script> alert ('input is not an 8-digit number ') </script>"); 9} 10}


 

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.