# | Likes | Tech tags | Title | Creator | Created date |
---|---|---|---|---|---|
1 | 0 |
2022-12-19 19:13
|
Does the matching using std::regex_search
#include<regex>
#include<string>
int main() {
std::string text = "Our coordinates are (a=123, b=5432), and we have some values too";
std::regex pattern("a=(\\d+), b=(\\d+)");
std::smatch match;
if(std::regex_search(text, match, pattern)) {
std::string a = match[1]; // acquires value "123"
std::string b = match[2]; // acquires value "5432"
}
return 0;
}
classes | ||
std::regex |
en.cppreference.com | cplusplus.com |
std::smatch |
en.cppreference.com | cplusplus.com |
std::string |
en.cppreference.com | cplusplus.com |
functions | ||
std::regex_search |
en.cppreference.com | cplusplus.com |
Construct a regex pattern with some groups. Find a segment of some string that matches said pattern and fetch the parts that match the groups specified by the pattern.