What is a regular expression?

Source: Internet
Author: User
Tags expression engine

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:

  1. What is a regular expression?
  2. Getting started with regular expressions: match a Fixed Single Character
  3. Getting started with regular expressions: matching any single character
  4. Getting started with regular expressions: Use character groups
  5. Getting started with regular expressions: Use character ranges in character groups
  6. Getting started with regular expressions: Use of assense character groups
  7. Getting started with regular expressions: matching null characters
  8. Getting started with regular expressions: Match one or more characters
  9. Regular Expression: matches zero or multiple characters.
  10. Regular Expression entry: matches zero or one string.
  11. Getting started with regular expressions: Match fixed numbers of Characters
  12. Getting started with regular expressions: match the number of characters in a range
  13. Getting started with regular expressions: greedy matching
  14. Getting started with regular expressions: inert matching
  15. Entry to Regular Expressions: two matching Modes
  16. Getting started with regular expressions: match word boundaries
  17. Getting started with regular expressions: boundary definition and relativity
  18. Getting started with regular expressions: Match non-word boundaries
  19. Getting started with regular expressions: match the beginning and end of a text
  20. Entry to regular expression: submode
  21. Regular Expression entry: "or" Match
  22. Getting started with regular expressions: replacing with referenced text
  23. Getting started with regular expressions: unmatched
  24. Regular Expression Summary: Regular Expressions in JavaScript
  25. Regular Expression Summary: advanced application of regular expressions in js

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.