Regular expression operations
Regular expression utilities.
Name | Description |
---|---|
operator""_re(const char *s, size_t sz) | "foo"_re -> std::regex{"foo"} |
replace(std::regex re, extra::ptr< const char > fmt) | std::string replace by regex |
each_match(std::regex re) | Match input with re , and generate each match as output. |
split(std::regex re) | Split input based on a std::regex , generating each substring. Note a std::string variant is available. |
operator""_re(const char *s, size_t sz)
<piped/regex.hpp>
std::regex piped::literals::regex::operator""_re(const char *s, size_t sz)
Description
"foo"_re -> std::regex{"foo"}
Example:
using namespace piped::literals;
auto s = "ab" | replace(".b"_re, "x"); // => "xb"
Parameter | ||
---|---|---|
s | const char * | |
sz | size_t |
replace(std::regex re, extra::ptr< const char > fmt)
<piped/regex.hpp>
detail::replace_ piped::replace(std::regex re, extra::ptr< const char > fmt)
Description
std::string
replace by regex
Example:
std::string s = "abc";
s |= replace(".b", "xb");
s == "xbc"; // => true
(Note that std::regex_replace
expects a null-terminated string, and thus std::string_view
can't be used for fmt
input here.)
Returns |
---|
A new string with replacement done. |
Parameter | ||
---|---|---|
re | std::regex | A std::regex . |
fmt | extra::ptr< const char > | const char* convertible replacement format, as per std::regex_replace |
each_match(std::regex re)
<piped/regex.hpp>
detail::each_match_ piped::each_match(std::regex re)
Description
Match input with re
, and generate each match as output.
auto v = "X:Y:Z:"
| each_match(".:"_re)
| map_nth(0)
| map_to<std::string_view>
| collect<std::vector>;
// Produces ["X:", "Y:", "Z:"] as a vector of string_view of
// the original string.
Returns |
---|
Match generator |
Parameter | ||
---|---|---|
re | std::regex | A std::regex . |
split(std::regex re)
<piped/regex.hpp>
auto piped::split(std::regex re)
Description
Split input based on a std::regex
, generating each substring. Note a std::string
variant is available.
Parameter | ||
---|---|---|
re | std::regex | Regular expression to match split delimiter |