Regular Expression?

Source: Internet
Author: User
Regular Expression?

Regular ExpressionsProgramBut not all developers know this. Regular Expressions can be seen as small ones with specific functionsProgramming Language: Locate a substring in a large string expression. It is not a new technology. It was initially developed in a Unix environment and used more with Perl. Microsoft has transplanted it to Windows. So far, it has been used in many scripting languages. However, many. Net classes in the system. Text. regularexpressions namespace support regular expressions .. All parts of the Net Framework use regular expressions. For example, a regular expression is used in the validation Server Control of ASP. NET.

The regular expression language is a language specifically used for string processing. It has two functions:

● A group of escape characters used to identify Character TypesCode. You may be familiar with the * character in the DOS expression to indicate any sub-string (for example, the doscommand dir re * will list all files whose names start with RE ). Regular Expressions use many sequences similar to * to represent "any character", "a word", and "an optional character.

● One system. In the search operation, it combines the sub-string and the various parts of the intermediate result.

 

Using Regular Expressions, you can perform many complex and advanced operations on strings, such:

● Differentiate (can be a tag or delete) All repeated words in a string. For example, convert the computer books to the computer books.

● Convert all words to the title format. For example, convert this is a title to this is a title.

● Convert all words longer than three characters into the title format. For example, convert this is a title to this is a title.

● Make sure the sentence has the correct capital format.

● Differentiate each element of a URI (for example, http://www.wrox.com/, and extract the name of the computer name extension file from the collaborators ).

 

Of course, these are all tasks that can be executed in C # using system. String and system. Text. stringbuilder methods. However, in some cases, a considerable amount of C # code is required. If regular expressions are used, these codes can be compressed into several lines of code. Actually, an object system is instantiated. text. regular Expressions. regEx (or even simpler: Call the static RegEx () method) to send it the string to be processed and a regular expression (this is a string, contains commands written in the Regular Expression Language.

 

A regular expression string initially looks like a normal string, but it contains an escape sequence and other characters with specific meanings. For example, sequence \ B indicates the start and end of a word (Word boundary, you can write the regular expression \ BTH (that is, the boundary of the sequential word is-t-h ). If you want to search for all words ending with th, you can write th \ B (sequence T-h-word boundary ). However, regular expressions are much more complex than this, including tool programs that can be found to store part of the text in search operations. This section only describes the functions of regular expressions.

 

Assume that the application needs to convert the US phone number to the international format. In the United States, the phone number format is 314-123-1234, often written (314) 123-1234. When converting the country format to an international format, you must add + 1 (Country Code of the United States) to the front of the phone number and add the area code with brackets: + 1 (314) 123-1234. This is not complicated when searching and replacing, but if you want to use the string class to complete this conversion, you need to write some code (this indicates that you must use system. the Regular Expression Language can construct a short string to express the above meaning.

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.