Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions CPP11.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ C++11 includes the following new library features:
- [memory model](#memory-model)
- [std::async](#stdasync)
- [std::begin/end](#stdbeginend)
- [regular expressions](#regex)

## C++11 Language Features

Expand Down Expand Up @@ -969,6 +970,39 @@ auto a = CountTwos(vec); // 2
auto b = CountTwos(arr); // 1
```

### regular expressions
The <regex> library offers tools to handle regular expressions, supporting POSIX and other common syntaxes for regular expressions.

The std::regex class is initialized with a regular expression and handles parsing the regular expression.
std::regex_search() looks for a regex inside a given string, and std::regex_replace() replaces any instances of the regex inside the given string.
std::regex_iterator and std::regex_token_iterator allow iteration through matches and submatches (respectively) within the string.

The following example illustrates the use of regular expressions to identify an email address:

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

int main() {

// Define a simple regex pattern for an email address
std::regex email_pattern(R"([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})");

// Input string to check
std::string email = "example@example.com";

// Check if the input string matches the pattern
if (std::regex_match(email, email_pattern)) {
std::cout << email << " is a valid email address." << std::endl;
} else {
std::cout << email << " is not a valid email address." << std::endl;
}

return 0;
}



## Acknowledgements
* [cppreference](http://en.cppreference.com/w/cpp) - especially useful for finding examples and documentation of new library features.
* [C++ Rvalue References Explained](http://web.archive.org/web/20240324121501/http://thbecker.net/articles/rvalue_references/section_01.html) - a great introduction I used to understand rvalue references, perfect forwarding, and move semantics.
Expand Down