Example of applying the regular expression in the appendix (in Collection) provided by yuanyou

Source: Internet
Author: User
ArticleDirectory
    • Example 1. Generate a hyperlink Based on the name and URL
    • Example 2. Generate a form
    • Example 4: generate the internal code of the class

Review solicitation Stickers: http://www.cnblogs.com/BeginnerClassroom/archive/2010/07/30/1788649.html

Appendix collection Stickers: http://www.cnblogs.com/BeginnerClassroom/archive/2010/08/04/1792175.html

You are welcome to expand a part of the content of this book, which will be attached to the book in the form of an appendix.

Requirements:

    1. Closely around one or two centers;
    2. Clear logic and smooth writing;
    3. Consider the basics of beginners.
    4. It is recommended that the writing time be less than one week.

After I write everything, I put it there first. After a while, I read it and modify it again. It is basically smooth after so many times.

 

(PS: it will be signed, but there is no draft fee, because there is not much, not enough points. Of course, if you make a fortune, I will give it to you .)

Title Author Status
Research on modifying the font size of RichTextBox Li yilai Completed
Difference between delegation and Interface Tang fan Writing
XML format comment Capricornus Writing
Explicit interface implementation and comparison with abstract classes Gu lei Writing
     
     
. Net version change table Zhang Zhiming Writing
Character encoding Zhao Shijing Writing
     
Stream reading Huang zhibin Writing
Application of Regular Expressions in emeditor Liu yongfa Writing
Drawing Cache   To be selected
     

 

Regular Expression application instance

(Provided by Liu yongfa in this article)

Regular Expressions seem complex on the surface, but they are actually very simple. The core of a regular expression is the idea of matching. Replacement and traversal are only additional functions. Since I got started with regular expressions, I felt a lot more open-minded. Many operations can't help but come up with regular expressions.

In practical applications, I often use a small number of regular expressions, such as \ W, \ W, \ s, \ s, \ D, \ D, + ,*,? , [], {N, m}, etc., basically can meet most of my needs. Most people only use regular expressions in JS, vbs, And. net. In fact, the application scope of regular expressions is far more than that. For example, many text editors provide excellent support for regular expressions, so you do not need to writeProgramIt can be easily applied to daily development and writing. The following are some examples of my applications in emeditor for beginners.

Figure 1 emeditor Interface

Example 1. Generate a hyperlink Based on the name and URL

Original text:

Blog http://www.cnblogs.com/

Liu yongfa http://www.yongfa365.com/

Google http://www.google.cn/

Regular Expression:

(\ S +) \ s + (\ s +)

Replace:

<A href = "\ 2"> \ 1 </a>

Result:

<A href = "http://www.cnblogs.com/"> cnblogs </a>

<A href = "http://www.yongfa365.com/"> Liuyong method </a>

<A href = "http://www.google.cn/"> Google </a>

Note: because regular expressions (\ s +) \ s + (\ s +) have two parentheses, there are two groups. The first group matches the name and the second group matches the URL. Replace \ 1 in the expression with the name matched by the first group (for example, "blog"), and \ 2 with the URL matched by the second group (for example, "http://www.cnblogs.com /"), in this way, we get the expected result [1].

Example 2. Generate a form

Original text:

Username

Password userpassword

Regular Expression:

(\ S +) \ s + (\ s +)

Replace:

<TD> \ 1: </TD> <input name = "TXT \ 2"/> </TD>

Result:

<TD> User name: </TD> <input name = "txtusername"/> </TD>

<TD> password: </TD> <input name = "txtuserpassword"/> </TD>

Note: This example is very similar to Example 1. \ 1 corresponds to the first group (for example, "username") and \ 2 corresponds to the second group (for example, "username ").

Example 3. generate an SQL statement

Original text:

123

234

345

Regular Expression:

(\ D +)

Replace:

Insert into card (Code, addtime) values ('\ 1', getdate ())

Replacement result:

Insert into card (Code, addtime) values ('20140901', getdate ())

Insert into card (Code, addtime) values ('20140901', getdate ())

Insert into card (Code, addtime) values ('20140901', getdate ())

Note: The regular expression (\ D +) matches each piece of data and corresponds to \ 1 in the replacement expression.

Example 4: generate an internal class Code

Original text:

Username

Password userpassword

Regular Expression:

(\ S +) \ s + (\ s +)

Replace:

String _ \ 2; \ N // <summary> \ N // \ 1 \ N // </Summary> \ npublic string \ 2 \ n {\ n get {return _ \ 2 ;} \ n set {_ \ 2 = value ;}\ n}

Result:

String _ username;

/// <Summary>

/// User Name

/// </Summary>

Public String Username

{

Get {return _ username ;}

Set {_ username = value ;}

}

String _ userpassword;

/// <Summary>

/// Password

/// </Summary>

Public String userpassword

{

Get {return _ userpassword ;}

Set {_ userpassword = value ;}

}

Note: although it looks complicated, its principles are the same as those above. After careful observation, we will find that there are back-to-reference characters \ 1 and \ 2, except that the text in the expression is longer and there is an additional line break \ n.

Are there few regular expressions used above, but they are very practical? Especially when there are dozens of rows and dozens of rows of data. To write a regular expression, observe the features of the original text. In many cases, we do not need to write a complete regular expression. It is enough. For example, in Example 1, the second (\ s +) in the regular expression (\ s +) \ s + (\ s +) matches the URL, in this text environment, you only need one (\ s +), and you do not need to write a bunch of complete regular expressions to match URLs.

Here, I just want to explain that regular expressions are not only a technology, but also a "thinking model ", it will promote part of Huawei's thinking after you use it again and again.

Liu yongfa

2010.8.8

Http://www.yongfa365.com/

[①] For the basic syntax of regular expressions, see Chapter 20th.

 

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.