Regular expressions do not seem as important as a language or technology. You cannot write an application only by using them. However, they are always used in your development process, whether for form verification, highlighting search results, or URL address ing. Almost all languages support it to varying degrees. As a result, it shows its position in the field of text matching.
Regular expressions should be a lightweight skill that developers should master. However, the odd matching pattern always reminds people of alien languages. In this article, I hope to share with you a wide range of examples to review and review regular expressions in a simple way.
What is a regular expression?
A regular expression is also called Pattern. It consists of a group of strings with specific meanings and is usually used to match and replace text.
Wiki: Regular Expression (Regular Expression, regex, or regexp, abbreviated as RE). It is also translated into Regular and Regular expressions. in computer science, it refers to a single string used to describe or match a series of strings that conform to a certain syntax rule. In many text editors or other tools, regular expressions are usually used to retrieve and/or replace text content that meets a certain pattern. Many programming languages Support string operations using regular expressions. For example, a powerful Regular Expression Engine is built in Perl. The concept of regular expressions was initially popularized by tools in Unix (such as sed and grep. Regular Expressions are abbreviated as "regex". The singular values include regexp and regex, And the plural values include regexps, regexes, and regexen.
Generally, if multiple matches exist in a text, the regular expression returns the first match. If global is set to true, all matches are returned; the matching mode is case sensitive. If ignore case is set to true, The case sensitivity is ignored.
Sometimes Hou regular expressions are also referred to as expressions, matching modes, or patterns. They can be exchanged. Global and ignore case are both true by default.
Regular Expression history
The "originator" of regular expressions may be traced back to early research by scientists on the working principles of human nervous systems. Warren McCulloch from New Jersey and Walter Pitts, born in Detroit, developed a new mathematical method to describe neural networks, they innovatively describe neurons in the nervous system as small and simple automatic control elements, thus making a great work innovation.
In 1956, a math scientist named Stephen Kleene, was born in Hatford, one of the most beautiful cities in the United States, called Mark Twain, based on Warren McCulloch and Walter Pitts's early work, he published a paper titled neural network event representation, this model is described using mathematical symbols called regular expression sets, and the concept of regular expressions is introduced. A regular expression is used as an expression to describe it as an "Algebra of a regular set". Therefore, the term "Regular Expression" is used.
Later, people found that the work could be applied to other aspects. Ken Thompson applied this result to some early research on computational search algorithms. Ken Thompson is the principal inventor of Unix, the father of the famous Unix. The father of Unix introduced the symbol system into the editor QED, followed by the editor ed on Unix, and finally introduced grep. Jeffrey Friedl explained this in his book Mastering Regular Expressions (2nd edition). If you want to learn more about the theory and history of Regular Expressions, we recommend that you read this book.
Since then, regular expressions have been widely used in UNIX or UNIX-like tools, such as Perl. Perl Regular Expressions are derived from the regex compiled by Henry Spencer and have evolved into pcre (Perl Compatible Regular Expressions ), pcre is a library developed by Philip Hazel and used by many modern tools. The first utility of regular expressions is the qed editor in Unix.
Then, regular expressions have been widely used and developed in a variety of computer languages or fields, and have evolved into a beautiful and sound lark in the current computer technology forest.
The above is a historical description of the origin and development of regular expressions. Up to now, regular expressions still play a very important role in text-based editors and search tools.
In the past 60 years, regular expressions have gradually evolved from fuzzy and profound mathematical concepts to major functions in various computer tools and software packages. Not only do many UNIX tools support regular expressions, but in the past two decades, the idea and application of regular expressions in the Windows camp have been supported and embedded in most Windows developer kits! From the regular expression in Microsoft Visual Basic 6 or Microsoft VBScript. in the. NET Framework, the support for regular expressions in WINDOWS products has grown to an unparalleled level. Currently, almost all Microsoft developers and all.. NET can all use regular expressions. If you are a computer language contact, you will be in the mainstream operating systems (* nix [Linux, Unix, etc.], Windws, HP, BeOS, etc) among the mainstream development languages (PHP, C #, Java, C ++, VB, Javascript, Ruby, etc.) and hundreds of millions of applications, you can see the graceful dance of the regular expression.
Additional reading
The topic list of this article is as follows:
- What is a regular expression?
- Getting started with regular expressions: match a Fixed Single Character
- Getting started with regular expressions: matching any single character
- Getting started with regular expressions: Use character groups
- Getting started with regular expressions: Use character ranges in character groups
- Getting started with regular expressions: Use of assense character groups
- Getting started with regular expressions: matching null characters
- Getting started with regular expressions: Match one or more characters
- Regular Expression: matches zero or multiple characters.
- Regular Expression entry: matches zero or one string.
- Getting started with regular expressions: Match fixed numbers of Characters
- Getting started with regular expressions: match the number of characters in a range
- Getting started with regular expressions: greedy matching
- Getting started with regular expressions: inert matching
- Entry to Regular Expressions: two matching Modes
- Getting started with regular expressions: match word boundaries
- Getting started with regular expressions: boundary definition and relativity
- Getting started with regular expressions: Match non-word boundaries
- Getting started with regular expressions: match the beginning and end of a text
- Entry to regular expression: submode
- Regular Expression entry: "or" Match
- Getting started with regular expressions: replacing with referenced text
- Getting started with regular expressions: unmatched
- Regular Expression Summary: Regular Expressions in JavaScript
- Regular Expression Summary: advanced application of regular expressions in js