C # Regular Expression simple case resolution

Source: Internet
Author: User

Regular expressions are primarily used for the manipulation of strings.

1.regex.ismatch: Determines whether the specified string conforms to a regular expression.

2.regex.match: Extracts a matching string that can only be extracted to the first conforming string. You can also use groups to extract them.

The regular expressions are grouped by parentheses so that information about the group can be obtained at the time of extraction. The returned type is match, which is the value to get.

Group information is distinguished by an index where 0 represents the entire matched character and 1 represents the first character in parentheses.

String sss = Regex.match ("", "A (.)" D "). GROUPS[1]. Value;

3.regex.matches, extracts all the characters that match. The return value is MatchCollection. The operation matches the match.

4. The writing of regular expressions is related to the analysis of business, and it is necessary to analyze the law concretely.

5.| has a low priority.

"A|BCD", will match to a or BCD.

  

. NET uses Unicode matching mode by default and can be added to the limit by Regexoption enumeration
Unicode encoding denotes "full-width" input
Remove duplicate data Here the \1 represents the self-reference, which represents the reference (.), which means the counter-reference, which is also represented (.), except that the reference in a different place requires a different expression
This will replace the whole of a with a single A,BC.
//(.) Matches all characters except the carriage return line, \1 is self-referencing (.), + indicates one or more occurrences, so that no matter how many times the character appears, it will be replaced by (.), which completes the business requirement string s = "AAAABBBBCCC"; Textbox1.appendtext (Regex.Replace (S, @ "(.) \1+ "," $ "));
The rule of the mailbox is to include @ and. string email = "[email protected]"; You need to escape the. Point
Match all the characters by \w, connect to the @, connect to the \w, then connect to the \w textbox1.appendtext (regex.ismatch (email, @ "\[email protected]\w+\.[ A-za-z]+ "). ToString ());

String msg = ""; Qualifier after add? Represents the end of greedy mode, as few matches as possible//By default is greedy mode, as many matches as match m1 = Regex.match (msg, "(.) +?"); To determine if the ZIP code is valid for 5 digits, you need to use ^$ to make an exact match//^ represents the beginning of the $ expression ending together with the expression to exactly match the Regex.IsMatch ("", "^[0-9]{6}$"); Determine if the ID number can be 15-bit or 18-bit regex.ismatch ("", @ "[\d]{15}|[ \D]{17}[0-9XX] ");

  

C # Regular Expression simple case resolution

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.