A regular expression is used to search for similar words. A regular expression is used to search for words.
This article demonstrates a variety of Regular Expression structures and techniques used in practical applications to familiarize yourself with the application of regular expressions.
Problem description:
In this instance, you need to solve the following problems.
1. You want to find all the color and color in a string.
2. Find any of the three words ending with "at": bat, cat, or rat.
3. Find the word ending with phobia.
4. Common variants of the Target name "Steven": Steve, Steven, and Stephen.
5. All common forms for matching the term "regular expression.
Solution:
The following lists the regular expressions used to solve these problems in sequence. All these solutions use case-insensitive options.
Question 1:Color and color
\ Bcolou? R \ B
Regular option: case insensitive
Regular genre:. NET, Java, JavaScript, PCRE, Perl, Python, Ruby
Question 2:Bat, cat, or rat
\ B [wb] at \ B
Regular option: case insensitive
Question 3:Word ending with "phobia"
\ B \ w * phobia \ B
Regular option: case insensitive
Question 4:Steve, Steven, and Stephen
\ BSte (? : Ven? | Phen) \ B
Question 5:Variation of "regular expression"
\ Breg (? : Ular·Expressions? | Ex (? : Ps? | E [sn])?) \ B
Regular option: case insensitive
Regular genre:. NET, Java, JavaScript, PCRE, Perl, Python, Ruby
Resolution:
\ B # determine the boundary position of a word
Reg # matching "reg"
(? : # Group but not captured
Ular\# Matching "ular"
Expressions? # Match "expression" or "expressions"
| # Or:
Ex # match "ex"
(? : # Group but not captured
Ps? # Match "p" or "ps"
| # Or:
E [sn] # match "es" or "en"
)? # End a non-capturing group. The entire group is optional.
) # End of a non-capturing Group
\ B # determine the boundary position of a word
Note:The five regular expressions use the word boundary (<\ B>) to ensure that only the entire word is matched.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.