Regular expressions outline What a regular expression is. _ Regular Expressions

Source: Internet
Author: User
Overview of regular Expressions

Regular expressions are widely used in programming languages, especially for processing strings. such as matching strings, finding strings, replacing strings, and so on. It can be said that a regular expression is a piece of text or a formula, it is used to describe a pattern to match a class of strings, and the formula has a certain pattern.
This section describes the basic concepts of regular expressions, the first regular expression, and the tool code architects Regex Tester that tests regular expressions.


what is a regular expression

Regular Expressions (Regular Expression) originated from the early studies of the human nervous system. Neuroscientists Warren McCulloch and Walter Pitts have developed a way to describe neural networks in a mathematical way. In 1956, Stephen Kleene, a mathematician, published a paper titled "The Representation of neural network events" and introduced the concept of "regular expression" in the paper. The paper says that regular expressions are expressions of "algebra of regular sets". Therefore, the term "regular expression" is used. The definition of a regular expression has several arguments, as follows:

A regular expression is a formula that matches a type of string in a pattern, mainly used to describe a string matching tool.

A regular expression describes a pattern of string matching. It can be used to check whether a string contains a seed string, to replace a matching substring, or to remove a substring from a string that matches a condition.

A regular expression is a literal pattern consisting of ordinary characters, such as characters A through z, and special characters, called metacharacters. A regular expression is used as a template to match a character pattern with the string being searched for.

Regular expressions are tools used to describe certain rules. These rules are often used to process a find or replace string in a string. In other words, regular expressions are code that records text rules.

A regular expression is a "string" that describes a feature and then verifies that another "string" conforms to this feature.
Readers who have learned the principles of compiling may be aware of uncertain finite automata (non-deterministic finite automaton, NFA) and finite automata (deterministic finite automaton, referred to as DFA). In fact, the regular expression is an indeterminate finite automaton. The biggest difference between NFA and DFA is their state transition function. The NFA can produce multiple interpretations of the same string, while the DFA has only one way of understanding. Because of this, the NFA may backtrack during the matching process, and the NFA is generally less efficient than the DFA. Therefore, when writing regular expressions, minimize backtracking to improve the efficiency of regular expressions.

If you have used Windows or DOS wildcard characters for file lookups * and?, then it is not difficult to understand regular expressions. If you need to find all Word documents, you might use an expression *.doc. Where the character * is a wildcard, it can represent any string. Regular expressions and wildcard characters are similar, and they can also be used to represent any character, such as a character. However, it is more accurate than wildcard characters.
In regular expressions, matching is the most commonly used word, which describes the regular expression action result. Given a piece of text or string, use a regular expression to find a string that matches a regular expression from text or a string. It is possible that there are more than one part of a literal or character that satisfies a given regular expression, at which point each such part is called a match. Among these, there are 3 types of matching:
Adjective matching, that is, a string matching a regular expression.

Verb matching, that is, matching regular expressions in text or strings.

A nominal match, that is, a part of a string that satisfies 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 program development environment, as well as many applications, can see the regular expression of such or such applications. Regular expressions are commonly used as follows:

Validates a string that verifies that a given string or substring conforms to the specified characteristics, such as verifying whether it is a legitimate mailing address, verifying that it is a legitimate HTTP address, and so on.

Finding a string that finds a string that matches a specified feature from a given text is more flexible than finding a fixed string.
A replacement string that replaces a substring with a specified feature in a given string with another string that is more powerful than a normal replacement.
Extracts a string that extracts a substring from a given string that matches the specified feature.

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.