A regular expression is a formula that matches a type of string in a pattern, mainly used to describe a string-matching tool
The
Regular expression Overview
Regular expressions are widely used in programming languages, especially for handling 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 the regular expression
Regular expression (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, primarily to describe a tool for string matching. 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. A
Regular expression is a tool 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 uses a "string" to describe a feature and then to verify that another "string" conforms to this feature. The
Reader of the principles of compilation may be aware of the uncertain finite automata (non-deterministic finite automaton, NFA) and the determination of finite automata (deterministic finite automaton, DFA). In fact, the regular expression is an indeterminate finite automaton. The biggest difference between an NFA and a DFA is that their state is turnedChange the 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 term that describes the result of a regular expression action. 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.
A verb match that matches a regular expression in a literal or string.
A nominal match, which is 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: The
validates the string, which verifies that the given string or substring conforms to the specified characteristics, such as verifying whether it is a legitimate mailing address, verifying whether it is a legitimate HTTP address, and so on.
finds a string that is more flexible than finding a fixed string, finding a string that matches the specified characteristics from the given text. The
replacement string, which replaces a substring with the specified feature in a given string with another string, is more powerful than a normal replacement. The
extracts a string that extracts substrings that match the specified characteristics from the given string.