-
Notifications
You must be signed in to change notification settings - Fork 0
Regex
Derek Snider edited this page May 19, 2026
·
1 revision
Regular expressions via std::regex, available through the madc:: namespace. The perl:: namespace also provides regex-powered grep and split.
int m = madc::regex_match(s, "[A-Za-z]+ [A-Za-z]+ [0-9]+");
// returns 1 if the ENTIRE string matches, 0 otherwiseint found = madc::regex_search(s, "[0-9]+");
// returns 1 if the pattern matches ANYWHERE in the stringstring result;
madc::regex_replace(result, source, pattern, replacement);
// replaces all occurrences; original is not modified#include <iostream>
int main() {
string s = "hello123";
int m = madc::regex_match(s, "hello[0-9]+");
cout << m << endl; // 1
string s2 = "foo bar baz";
int found = madc::regex_search(s2, "bar");
cout << found << endl; // 1
string result;
madc::regex_replace(result, "The quick brown fox", "quick|brown", "slow");
cout << result << endl; // The slow slow fox
return 0;
}perl::grep filters arrays by regex match. perl::split splits strings by regex delimiter. Both fall back to substring matching if the pattern isn't a valid regex.
array words;
php::explode(words, ",", "apple,banana,cherry,avocado");
array matches;
perl::grep(matches, "^a", words);
// matches: apple, avocadoInvalid regex patterns are caught internally — no crash or exception propagates to your program.
- Namespaces — overview of all namespace functions
- perl:: Namespace — regex grep and split
- ← Back to Home