In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to use Clear11 regular expression Library". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Basic usage
Code description
The most basic use, of course, is to define a regular expression and then use it.
The code uses regex to define a regular expression r that describes the word "test". It is a word because the metacharacter'\ b'is placed at both ends of "test" to match the beginning or end of the word. Because we code in the C++ environment, the actual code is "\ b".
Output result
Although there is a testing in the example sentence, a test is found correctly.
Use subexpressions
Regular expressions often contain subexpressions, that is, the part of an expression that is surrounded by parentheses.
Code description
The regular expression defined in the code contains two subexpressions that match the file name and the extension, respectively.
The matching result is also slightly different. When including a subexpression, use str (0) to get the whole of the matching result, use str (1) to be the first subexpression, and so on.
Output result
Matching iterator
In actual development, repeated lookups often occur, and sregex_iterator is provided in the expression library to deal with this problem.
Code description
First define the regular expression as a word that starts with test. Then define two sregex_iterator. One is used for matching search, and the other is used for finished judgment.
Output result
As you can see, the match happened twice. But it is a pity that all the matching parts are displayed. Take it easy.
Subexpression + iterator
Take a look at an example of repeating the different filenames of a lookup statement.
Code description
The code combines the techniques of subexpressions and iterators.
Output result
That's what it looks like.
This is the end of the content of "how to use the regular expression Library of Category 11". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.