Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Y
YAT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Control System
Libraries
YAT
Commits
04dca8fc
Commit
04dca8fc
authored
Dec 22, 2020
by
Stéphane Poirier
Browse files
Options
Downloads
Patches
Plain Diff
regex samples
parent
686912f4
Branches
Branches containing commit
Tags
release_1_1_0
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
samples/regex/pom.xml
+2
-2
2 additions, 2 deletions
samples/regex/pom.xml
samples/regex/src/regex_test.cpp
+12
-11
12 additions, 11 deletions
samples/regex/src/regex_test.cpp
with
14 additions
and
13 deletions
samples/regex/pom.xml
+
2
−
2
View file @
04dca8fc
...
...
@@ -24,8 +24,8 @@
</includePaths>
<options>
<!--option>-Wno-uninitialized</option-->
<option>
-Wno-unused-parameter
</option>
<option>
-Wno-unused-variable
</option>
<
!--
option>-Wno-unused-parameter</option
--
>
<
!--
option>-Wno-unused-variable</option
--
>
</options>
</cpp>
</configuration>
...
...
This diff is collapsed.
Click to expand it.
samples/regex/src/regex_test.cpp
+
12
−
11
View file @
04dca8fc
...
...
@@ -26,13 +26,11 @@
typedef
yat
::
StringFormat
_strf
;
//-----------------------------------------------------------------------------
void
match_
web_addr
(
const
yat
::
String
&
in
)
void
match_
pattern
(
const
yat
::
String
&
in
)
{
// Regex test
yat
::
StringFormat
sfmt
(
"'{}' is a regular web address: {}"
);
sfmt
.
format
(
in
);
yat
::
Regex
re
(
R"(www\.[-_[:alnum:]]+\.[[:lower:]]{2,4})"
,
yat
::
Regex
::
extended
);
yat
::
Regex
re
(
R"(www\.[-_[:alnum:]]+\.[[:lower:]]{2,4})"
);
yat
::
StringFormat
sfmt
(
"'{}' is an exact match of '{}': {}"
);
sfmt
.
format
(
in
).
format
(
re
.
pattern
());
std
::
cout
<<
sfmt
.
format
(
re
.
match
(
in
))
<<
std
::
endl
;
}
...
...
@@ -105,7 +103,7 @@ void replace_test(const yat::String& in, const yat::String& from,
{
yat
::
Regex
re
(
from
);
yat
::
String
out
=
re
.
replace
(
in
,
to
,
mflags
);
std
::
cout
<<
_strf
(
"Input string: {}. Search for: {}. Replace by: {}.
Resul
t: {}"
)
std
::
cout
<<
_strf
(
"Input string: {}. Search for: {}. Replace by: {}.
Outpu
t: {}"
)
.
format
(
in
).
format
(
from
).
format
(
to
).
format
(
out
)
<<
std
::
endl
;
}
...
...
@@ -120,10 +118,10 @@ int main(int argc, char* argv[])
coordinates_parser
(
"Rect(0,0),-[659,494]"
);
std
::
cout
<<
std
::
endl
;
match_
web_addr
(
"ww.cppreference.com"
);
match_
web_addr
(
"www.cppreference.info"
);
match_
web_addr
(
"www.cppreference.Com"
);
match_
web_addr
(
"www.cppreference.com"
);
match_
pattern
(
"ww.cppreference.com"
);
match_
pattern
(
"www.cppreference.info"
);
match_
pattern
(
"www.cppreference.Com"
);
match_
pattern
(
"www.cppreference.com"
);
std
::
cout
<<
std
::
endl
;
extract_submatches_with_iterator
(
"http://www.cppreference.com/w/cpp"
);
...
...
@@ -138,10 +136,13 @@ int main(int argc, char* argv[])
repeated_searches
(
"Speed: 366, Mass: 35.Speed: 378; Mass: 32!
\n
Speed: 400, Mass: 30"
);
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
"A few replace examples...
\n
"
<<
std
::
endl
;
replace_test
(
"ga bu zo meu"
,
"zo"
,
"zozo"
);
replace_test
(
"ga bu zo meu"
,
"bu"
,
"$&!!"
);
replace_test
(
"ga bu zo meu"
,
"(ga)(.*)(meu)"
,
"$3$2$1"
);
replace_test
(
"ga bu zo meu"
,
"(ga) (bu) (zo) (meu)"
,
"$4 $3 $2 $1"
);
replace_test
(
"ga bu zo meu"
,
"bu zo"
,
"$'$0$`"
);
std
::
cout
<<
"In the next example, non matching strings are not copied into the output"
<<
std
::
endl
;
replace_test
(
"ga bu zo meu"
,
"zo"
,
"zozo"
,
yat
::
Regex
::
format_no_copy
);
replace_test
(
"ga 1000€"
,
"ga [0-9]+€"
,
"bu 1100$$ > $0 !"
);
std
::
cout
<<
std
::
endl
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment