Home >Backend Development >C++ >How Can I Use Regular Expressions to Match an Entire String Exactly?
To ensure that the regular expression is accurately matched the entire string, two special characters can be used:
and. The beginning of the string () matching the beginning of the string, the US dollar symbol (^
) match the end of the string. By using these two characters at the same time, the matching limit can be limited to the string that is fully matched with the query. $
^
For example, if you want to search for movies with "Red October" (not distinguished), you can use the following regular expression: $
This expression only matches the string that starts with "Red October" and ended with "Red October". It does not match strings such as "The Hunt For Red October" or "Red October Night".
<code>^Red October$</code>Consider the sensitivity of the lower case
By default, the regular expression distinguishes the case. This means that "Red October" and "Red October" will be regarded as different matching items. If you want to searches that do not distinguish between or lowercase, you can use the modifier. This modifier tells the regular expression engine that ignores the appliance when performing matching.
code example (?i)
modifier in Python:
This code will print "matching failure", because the string "The Hunt For Red October" is not fully matched with the mode. If the string is changed to "Red October", the code will be printed "successfully".The above is the detailed content of How Can I Use Regular Expressions to Match an Entire String Exactly?. For more information, please follow other related articles on the PHP Chinese website!