Home  >  Article  >  Backend Development  >  A brief analysis of subexpressions, subexpression counting, and branch usage (regular expressions)

A brief analysis of subexpressions, subexpression counting, and branch usage (regular expressions)

巴扎黑
巴扎黑Original
2017-04-20 18:06:051553browse

Subexpressions

It is often useful to separate an expression into several subexpressions, for example, to mean "At least one of these strings needs to match exactly. "This can be done using parentheses, in the same way as in mathematical expressions.

For example:

(very) *large

can match "large", "very large", "very very large", etc.

Subexpression count

You can use a numeric expression in curly braces {} to specify the number of times the content is allowed to be repeated. You can specify an exact number of repetitions ({3} indicates the number of repetitions), or a range of repetitions ({2,4} indicates repetitions 2 to 4 times), or an open-bottom repetition range ({2,} means to repeat it at least twice).

For example:

(very){1,3}

means matching "very", "very very" and "very very very".

Branch

You can use a vertical bar in a regular expression to represent a selection. For example, if you want to match com, edu, or net, you can use the following expression:

com|edu|net

The above is the detailed content of A brief analysis of subexpressions, subexpression counting, and branch usage (regular expressions). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn