What is a regular expression.

Source: Internet
Author: User
Tags valid email address

Regular Expression Overview

Regular Expressions are widely used in programming languages, especially for processing strings. Such as matching strings, searching strings, and replacing strings. It can be said that a regular expression is a piece of text or a formula used to describe a formula that matches a type of string in a certain pattern, and the formula has a certain pattern.
This section describes the basic concepts of regular expressions, the first regular expression, and the Code verification ts Regex Tester tool for testing regular expressions.


What is a regular expression?

Regular Expressions (Regular Expression) originated from early studies in the human nervous system. Neuroscientists Warren McCulloch and Walter Pitts have developed a mathematical method to describe neural networks. In 1956, the mathematician Stephen Kleene published a paper titled "neural network event representation" and introduced the concept of "regular expression. In this paper, the regular expression is the expression of "the algebra of the regular set. Therefore, the term "Regular Expression" is used. The definition of a regular expression can be described as follows:

Regular Expressions are formulas used to match a type of strings in a certain pattern. They are mainly used to describe the string matching tools.

A regular expression describes a string matching pattern. It can be used to check whether a string contains a seed string, replace matched substrings, or retrieve substrings that meet certain conditions from a string.

A regular expression is a text mode consisting of common characters (such as characters a to z) and special characters (called metacharacters. A regular expression is used as a template to match a character pattern with the searched string.

Regular Expressions are tools used to describe certain rules. These rules are often used to search for or replace strings in strings. In other words, a regular expression is the code that records text rules.

A regular expression uses a "string" to describe a feature, and then verifies whether another "string" matches this feature.
Readers who have learned how to compile may be aware of Non-terministic finite Automation (NFA) and deterministic finite Automation (DFA ). In fact, a regular expression is an uncertain finite automatic machine. The biggest difference between NFA and DFA is their state conversion functions. NFA can generate multiple ways of understanding the same string, while DFA has only one way of understanding. Because of this, NFA may backtrack in the matching process, and the efficiency of NFA is generally lower than that of DFA. Therefore, when writing a regular expression, minimize backtracking to improve the efficiency of the regular expression.

If you have used wildcards * And? For file search in Windows or DOS ?, It is not difficult to understand regular expressions. If you need to search for all Word documents, the expression *. doc may be used. The character * is a wildcard, which can represent any string. A regular expression is similar to a wildcard. It can also use some characters (such as.) to represent any character. However, it is more accurate than a wildcard.
In a regular expression, matching is the most commonly used word, which describes the results of the regular expression action. Given a piece of text or string, use a regular expression to find the string that matches the regular expression from the text or string. It is possible that more than one part of the text or character Meets the given regular expression, and each such part is called a match. There are three types of matching:
A string matches a regular expression.

Verb matching: match a regular expression in a text or string.

A noun match is a part of a string that meets a given regular expression.

Regular Expressions are widely used, especially in string processing. At present, regular expressions have been widely used in many software applications, such as Linux, Unix, HP and other operating systems, C #, PHP, Java and other programming environments, in many applications, You can see applications with regular expressions in one way or another. Common applications of regular expressions are as follows:

A verification string is used to verify whether a given string or substring meets the specified features, such as verifying whether it is a valid email address or a valid HTTP address.

It is more flexible and convenient to search for strings that match the specified features from a given text.
Replace the character string, that is, replace the child string that matches the specified feature in the given string with another character string, which is more powerful than the normal replacement.
Extract A string, that is, extract a substring that meets the specified features from a given string.

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.