CPPSOBES Telegram 17
Regular expressions library (since C++11)

Библиотека регулярных выражений предоставляет класс, представляющий регулярные выражения, которые являются своего рода мини-языком, используемым для выполнения сопоставления шаблонов в строках.

#include <iostream>
#include <iterator>
#include <regex>
#include <string>

int main()
{
std::string s = "Some people, when confronted with a problem, think "
"\"I know, I'll use regular expressions.\" "
"Now they have two problems.";

std::regex self_regex("REGULAR EXPRESSIONS",
std::regex_constants::ECMAScript | std::regex_constants::icase);
if (std::regex_search(s, self_regex))
std::cout << "Text contains the phrase 'regular expressions'\n";

std::regex word_regex("(\\w+)");
auto words_begin =
std::sregex_iterator(s.begin(), s.end(), word_regex);
auto words_end = std::sregex_iterator();

std::cout << "Found "
<< std::distance(words_begin, words_end)
<< " words\n";

const int N = 6;
std::cout << "Words longer than " << N << " characters:\n";
for (std::sregex_iterator i = words_begin; i != words_end; ++i)
{
std::smatch match = *i;
std::string match_str = match.str();
if (match_str.size() > N)
std::cout << " " << match_str << '\n';
}

std::regex long_word_regex("(\\w{7,})");
std::string new_s = std::regex_replace(s, long_word_regex, "[$&]");
std::cout << new_s << '\n';
}

https://en.cppreference.com/w/cpp/regex

#cpp #programming

@cppsobes



tgoop.com/cppsobes/17
Create:
Last Update:

Regular expressions library (since C++11)

Библиотека регулярных выражений предоставляет класс, представляющий регулярные выражения, которые являются своего рода мини-языком, используемым для выполнения сопоставления шаблонов в строках.

#include <iostream>
#include <iterator>
#include <regex>
#include <string>

int main()
{
std::string s = "Some people, when confronted with a problem, think "
"\"I know, I'll use regular expressions.\" "
"Now they have two problems.";

std::regex self_regex("REGULAR EXPRESSIONS",
std::regex_constants::ECMAScript | std::regex_constants::icase);
if (std::regex_search(s, self_regex))
std::cout << "Text contains the phrase 'regular expressions'\n";

std::regex word_regex("(\\w+)");
auto words_begin =
std::sregex_iterator(s.begin(), s.end(), word_regex);
auto words_end = std::sregex_iterator();

std::cout << "Found "
<< std::distance(words_begin, words_end)
<< " words\n";

const int N = 6;
std::cout << "Words longer than " << N << " characters:\n";
for (std::sregex_iterator i = words_begin; i != words_end; ++i)
{
std::smatch match = *i;
std::string match_str = match.str();
if (match_str.size() > N)
std::cout << " " << match_str << '\n';
}

std::regex long_word_regex("(\\w{7,})");
std::string new_s = std::regex_replace(s, long_word_regex, "[$&]");
std::cout << new_s << '\n';
}

https://en.cppreference.com/w/cpp/regex

#cpp #programming

@cppsobes

BY С++ Собеседования


Share with your friend now:
tgoop.com/cppsobes/17

View MORE
Open in Telegram


Telegram News

Date: |

Ng was convicted in April for conspiracy to incite a riot, public nuisance, arson, criminal damage, manufacturing of explosives, administering poison and wounding with intent to do grievous bodily harm between October 2019 and June 2020. End-to-end encryption is an important feature in messaging, as it's the first step in protecting users from surveillance. Co-founder of NFT renting protocol Rentable World emiliano.eth shared the group Tuesday morning on Twitter, calling out the "degenerate" community, or crypto obsessives that engage in high-risk trading. With Bitcoin down 30% in the past week, some crypto traders have taken to Telegram to “voice” their feelings. Hui said the time period and nature of some offences “overlapped” and thus their prison terms could be served concurrently. The judge ordered Ng to be jailed for a total of six years and six months.
from us


Telegram С++ Собеседования
FROM American