Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/regex"

From cppreference.com
< cpp
m (Top: lc)
(Replaced content with "SCREW you Ads ..... Ads are every where ...... BOTS are everywhere .... Software job sucks ...... But this is page editing stuff is so much fun ..... you see, its ...")
Line 1: Line 1:
{{title|Regular expressions library}}
+
SCREW you Ads ..... Ads are every where ......
{{cpp/regex/navbar}}
+
  
The regular expressions library provides a class that represents [[enwiki:Regular expression|regular expressions]], which are a kind of mini-language used to perform pattern matching within strings. Almost all operations with regexes can be characterized by operating on several of the following objects:
 
  
* '''Target sequence'''. The character sequence that is searched for a pattern. This may be a range specified by two iterators, a null-terminated character string or a {{lc|std::string}}.
+
BOTS are everywhere ....
  
* '''Pattern'''. This is the regular expression itself. It determines what constitutes a match. It is an object of type {{lc|std::basic_regex}}, constructed from a string with special syntax. See {{lc|std::regex_constants::syntax_option_type|regex_constants::syntax_option_type}} for the description of supported syntax variations.
 
  
* '''Matched array'''. The information about matches may be retrieved as an object of type {{lc|std::match_results}}.
+
Software job sucks ......
  
* '''Replacement string'''. This is a string that determines how to replace the matches, see {{lc|std::regex_constants::match_flag_type|regex_constants::match_flag_type}} for the description of supported syntax variations.
 
  
===Main classes===
+
But this is page editing stuff is so much fun .....
  
These classes encapsulate a regular expression and the results of matching a regular expression within a target sequence of characters.
+
you see, its these little things that do put a smile on my face .....
  
{{dsc begin}}
+
I dont ask for much ...... just some harmless fun .....
{{dsc inc | cpp/regex/dsc basic_regex }}
+
{{dsc inc | cpp/regex/dsc sub_match }}
+
{{dsc inc | cpp/regex/dsc match_results }}
+
{{dsc end}}
+
  
===Algorithms===
 
  
These functions are used to apply the regular expression encapsulated in a regex to a target sequence of characters.
+
Hey Hey .... don't blame mee ..... I am just having some "harmless" fun ....
  
{{dsc begin}}
+
hehehehehehehehehehehehehehehhe
{{dsc inc | cpp/regex/dsc regex_match }}
+
{{dsc inc | cpp/regex/dsc regex_search }}
+
{{dsc inc | cpp/regex/dsc regex_replace }}
+
{{dsc end}}
+
 
+
===Iterators===
+
 
+
The regex iterators are used to traverse the entire set of regular expression matches found within a sequence.
+
 
+
{{dsc begin}}
+
{{dsc inc | cpp/regex/dsc regex_iterator }}
+
{{dsc inc | cpp/regex/dsc regex_token_iterator }}
+
{{dsc end}}
+
 
+
===Exceptions===
+
 
+
This class defines the type of objects thrown as exceptions to report errors from the regular expressions library.
+
 
+
{{dsc begin}}
+
{{dsc inc | cpp/regex/dsc regex_error }}
+
{{dsc end}}
+
 
+
===Traits===
+
 
+
The regex traits class is used to encapsulate the localizable aspects of a regex.
+
 
+
{{dsc begin}}
+
{{dsc inc | cpp/regex/dsc regex_traits }}
+
{{dsc end}}
+
 
+
===Constants===
+
 
+
{{dsc begin}}
+
{{dsc namespace | std::regex_constants }}
+
{{dsc inc | cpp/regex/dsc syntax_option_type}}
+
{{dsc inc | cpp/regex/dsc match_flag_type}}
+
{{dsc inc | cpp/regex/dsc error_type}}
+
{{dsc end}}
+
 
+
===Example===
+
{{example
+
| code=
+
#include <iostream>
+
#include <iterator>
+
#include <string>
+
#include <regex>
+
 
+
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';
+
}
+
| output=
+
Text contains the phrase 'regular expressions'
+
Found 20 words
+
Words longer than 6 characters:
+
  confronted
+
  problem
+
  regular
+
  expressions
+
  problems
+
Some people, when [confronted] with a [problem], think
+
"I know, I'll use [regular] [expressions]." Now they have two [problems].
+
}}
+
 
+
{{langlinks|ar|de|es|fr|it|ja|ko|pt|ru|zh}}
+

Revision as of 12:10, 11 March 2022

SCREW you Ads ..... Ads are every where ......


BOTS are everywhere ....


Software job sucks ......


But this is page editing stuff is so much fun .....

you see, its these little things that do put a smile on my face .....

I dont ask for much ...... just some harmless fun .....


Hey Hey .... don't blame mee ..... I am just having some "harmless" fun ....

hehehehehehehehehehehehehehehhe