Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite56cc54

Browse files
authored
Update 6.1.regex.cpp
1 parent212f4f3 commite56cc54

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

‎code/6/6.1.regex.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@
1010
#include<iostream>
1111
#include<string>
1212
#include<regex>
13-
13+
usingnamespacestd;
1414
intmain() {
15-
std::string fnames[] = {"foo.txt","bar.txt","test","a0.txt","AAA.txt"};
15+
string fnames[] = {"foo.txt","bar.txt","test","a0.txt","AAA.txt"};
1616
// In C++, `\` will be used as an escape character in the string.
1717
// In order for `\.` to be passed as a regular expression,
1818
// it is necessary to perform second escaping of `\`, thus we have `\\.`
19-
std::regextxt_regex("[a-z]+\\.txt");
19+
regextxt_regex("[a-z]+\\.txt");
2020
for (constauto &fname: fnames)
21-
std::cout << fname <<":" <<std::regex_match(fname, txt_regex) <<std::endl;
21+
cout << fname <<":" <<regex_match(fname, txt_regex) << endl;
2222

23-
std::regexbase_regex("([a-z]+)\\.txt");
24-
std::smatch base_match;
23+
regexbase_regex("([a-z]+)\\.txt");
24+
smatch base_match;
2525
for(constauto &fname: fnames) {
26-
if (std::regex_match(fname, base_match, base_regex)) {
26+
if (regex_match(fname, base_match, base_regex)) {
2727
// the first element of std::smatch matches the entire string
2828
// the second element of std::smatch matches the first expression with brackets
2929
if (base_match.size() ==2) {
30-
std::string base = base_match[1].str();
31-
std::cout <<"sub-match[0]:" << base_match[0].str() <<std::endl;
32-
std::cout << fname <<" sub-match[1]:" << base << std::endl;
30+
string base = base_match[1].str();
31+
cout <<"sub-match[0]:" << base_match[0].str() << endl;
32+
cout << fname <<" sub-match[1]:" << base <<endl;
3333
}
3434
}
3535
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp