Microsoft's Regular Expression Tutorial (1): Introduction to Regular Expression

zhaozj2021-02-16  66

Cognitive regular expression

If there is no tax expression, it is not familiar with this term and concept. However, they are not so nice you imagine.

Recall how to find files on the hard disk. You will definitely use the * characters to help find the files you are looking for. • Characters match a single character in the file name, and * matches one or more characters. A pattern such as 'Data ?dat' can find the following file:

Data1.dat

Data2.dat

Datax.dat

Datan.dat

If you use * characters instead? The number of files found will be expanded. 'data * .dat' can match all the following file names:

Data.dat

Data1.dat

Data2.dat

Data12.dat

Datax.dat

Dataxyz.dat

Although this search file is certainly useful, it is also very limited. • The limited capacity of wildcards can make you have a concept of regular expressions, but the regular expression is more powerful, and more flexible.

Early origin of regular expressions

Regular expressions "ancestors" can have been traced back to an early study on how the human nervous system works. Two neur physiologists of Warren McCulloch and Walter Pitts have studied a mathematical way to describe these neural networks.

In 1956, a US mathematician called Stephen Kleene published an early working on McCulloch and Pitts, published a papers titled "Neural Network Emergencies", introduced the concept of regular expressions. Regular expressions are used to describe expressions he called "regular set algebra", so the term "regular expression" is used.

Subsequently, it is found that this work can be applied to some early studies using Ken Thompson's computing search algorithm, Ken Thompson is the main inventors of UNIX. The first practical application of the regular expression is the QED editor in UNIX.

As they said, the rest is a well-known history. Since then, until now the regular expression is an important part of the text-based editor and search tool.

Use regular expressions

In a typical search and alternative, the exact text to be found must be provided. This technique may be sufficient for simple search and replacement tasks in static text, but because it lacks flexibility, it is difficult to search for dynamic text, or even impossible.

Using regular expressions, you can:

Test a pattern of strings. For example, an input string can be tested to see if the string exists or a credit card number mode. This is called data validity verification. Replace the text. You can use a regular expression in the document to identify a particular text, then you can delete it, or replace it with another text. Extract a sub-string from the string based on the mode match. Can be used to find a specific text in the text or input field.

For example, if you need to search the entire Web site to delete some excessive materials and replace some HTML formatted tags, you can use the regular expression to test each file, see if there is a material or HTML you want to find in this file. Formatted tag. With this method, you can narrow the affected file range to those files that contain materials to be deleted or changed. You can then use the regular expression to delete the outdated material, and finally, you can use the regular expression again to find and replace those markers that need to be replaced.

转载请注明原文地址:https://www.9cbs.com/read-18844.html

New Post(0)