forked from VerbalExpressions/CppVerbalExpressions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.cpp
36 lines (29 loc) · 1.09 KB
/
example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "verbalexpressions.hpp"
#include <iostream>
#include <string>
int main() {
using verex::verex;
// Create an example of how to test for correctly formed URLs
verex expr = verex()
.search_one_line()
.start_of_line()
.then( "http" )
.maybe( "s" )
.then( "://" )
.maybe( "www." )
.anything_but( " " )
.end_of_line();
// Use VerEx's test() function to find if it matches
std::cout << (expr.test("https://www.google.com") ? "matches" : "doesn't match") << std::endl;
// Ouputs the actual expression used
std::cout << expr << std::endl;
// Create a test string
std::string replaceMe = "Replace bird with a duck";
// Create an expression that seeks for word "bird"
verex expr2 = verex().find("bird");
// Execute the expression
std::cout << expr2.replace(replaceMe, "duck") << std::endl;
// Shorthand string replace
std::cout << verex().find( "red" ).replace( "We have a red house", "blue" ) << std::endl;
return 0;
}