ArticleDirectory
- 1. Regular Expressions in. Net (msdn)
- Ii. re learning materials:
Reference:Ultrapico expresso is a very powerful regular expression construction, testing, andCodeGenerate a tool. It can parse and verify the regular expressions you have built, and output the parsing results. It provides performance testing tools and supports code generation such as C # and VB. The most important thing is that, he provides a very convenient and powerful regular expression syntax Building Panel. Even if you are unfamiliar with regular expressions, you can build the expected regular expression mode with its help. In addition, it also obtains the authorization code for free, and does not have to worry about cracking. The help documentation and regular expression library provided in the software can help you quickly upgrade from a regular expression cainiao to a regular expression master.
The latest version of ultrapico expresso provides the following powerful functions:
- Create Regular Expressions by selecting pre-written code snippets
- You can manually input the text or import the text from the file to test the text.
- Match is displayed in the tree structure, and capture groups and all captures in the group are displayed.
- Highlight matching text in the source file
- Syntax Error of Automatically Searching Regular Expression
- Generate VB, C #, or C ++ code
- Provides a library of common Regular Expressions
- Optimize Regular Expressions
- More...
First, check the Expresso operation interface:
The test mode is used to open the software. You can verify the Regular Expression and provide the RegEx analyzer function, you can easily view the details of your own regular expressions. In addition to the test mode, there are more powerful design mode and Expression Library (I think I can learn a lot from that expression library). You can understand the specific usage. You will find that through this tool, the curve for learning Regular Expressions will be smoother.
More learning experiences will be shared after Re and this tool are carefully learned. ---> To be continued.
1. Regular Expressions in. Net (msdn)
The syntax rules for regular expressions in different languages and frameworks are different. Here we only need to discuss the relevance of regular expressions on the. NET platform .. . Net uses regular expressions to process text.System. Text. regularexpressions. RegExObject Representation. To use a regular expression to process text, at least the following information must be provided to the Regular Expression Engine:
- The regular expression pattern to be identified in the text. in the. NET Framework, the regular expression mode is defined by special syntax or language. This syntax or language is compatible with Perl 5 Regular Expressions and some other functions are added, for example, match from right to left ..
- The text to be analyzed for the regular expression mode.
The RegEx class allows you to perform the following operations:
- Call the ismatch method to determine whether the input text has a regular expression pattern match.
- You can call the match or matches method to retrieve one or all text matches matching the regular expression pattern. The first method returns the match object that provides information about the matching text. The second method returns the matchcollection object, which contains a match object for each matching item found in the analyzed text.
- Replace the text that matches the Regular Expression Pattern by calling the replace method.
First, use an example to describe how to use the RegEx class in. Net:
Example 1: replace a substring
Using system; using system. Text. regularexpressions; public class example {public static void main () {string pattern = "(Mr \\.? | Mrs \\.? | Miss | MS \\.? ) "; String [] names = {" mr. henry Hunt "," Ms. sara Samuels "," Abraham Adams "," Ms. nicole Norris "}; foreach (string name in names) console. writeline (RegEx. replace (name, pattern, String. empty ));}}
Regular Expression mode (Mr \.? | Mrs \.? | Miss | MS \.? ) Can match any "Mr" or "Mr. "," Mrs "," mrs. "," Miss "," Ms ", or" ms. ". for RegEx. the replace method replaces the matched string with string. empty; in other words, it removes it from the original string.
Example 2: Mark duplicate words
Using system; using system. Text. regularexpressions; public class class1 {public static void main () {string pattern = @ "\ B (\ W + ?) \ S \ 1 \ B "; string input =" this is a nice day. What about this? This tastes good. I saw a dog. "; foreach (match in RegEx. matches (input, pattern, regexoptions. ignorecase) console. writeline ("{0} (duplicates '{1})' at position {2}", match. value, match. groups [1]. value, match. index) ;}// the example displays the following output: // This (duplicates 'this) 'at position 0 // A (duplicates 'a)' at position 66
Regular Expression mode \ B (\ W + ?) \ S \ 1 \ B can be interpreted as follows:
\ B: start at the word boundary
(\ W +): matches one or more word characters to form a group known as \ 1.
\ S: matches blank characters
\ 1: matches the substring of A group equal to \ 1
\ B: match the word boundary
The RegEx. Matches method is called by setting the regular expression option to regexoptions. ignorecase. Therefore, the matching operation is case insensitive. In this example, the substring "this" is identified as repeated.
Ii. re learning materials:
Msdn