Why does “[\s\S]” not working in C++11's regex
up vote
1
down vote
favorite
I have the code below this:
#include <string>
#include <regex>
int main(int argc, char const *argv) {
std::string s = "_apple_";
std::regex r1("_(\s|\S)+_");
std::regex r2("_[\s\S]+_");
std::regex r3("_.+_");
std::regex r4("_[pale]+_");
std::smatch sm;
printf("r1:%d r2:%d r3:%d r4:%dn",
std::regex_match(s, sm, r1),
std::regex_match(s, sm, r2),
std::regex_match(s, sm, r3),
std::regex_match(s, sm, r4));
return 0;
}
output:r1:1 r2:0 r3:1 r4:1
I can not understand why r2 is not match?
My environment is:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin.
regex c++11
|
show 2 more comments
up vote
1
down vote
favorite
I have the code below this:
#include <string>
#include <regex>
int main(int argc, char const *argv) {
std::string s = "_apple_";
std::regex r1("_(\s|\S)+_");
std::regex r2("_[\s\S]+_");
std::regex r3("_.+_");
std::regex r4("_[pale]+_");
std::smatch sm;
printf("r1:%d r2:%d r3:%d r4:%dn",
std::regex_match(s, sm, r1),
std::regex_match(s, sm, r2),
std::regex_match(s, sm, r3),
std::regex_match(s, sm, r4));
return 0;
}
output:r1:1 r2:0 r3:1 r4:1
I can not understand why r2 is not match?
My environment is:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin.
regex c++11
Interesting. On a GCC compiler, your code is working as expected.
– Tim Biegeleisen
Nov 19 at 13:40
but it does not work on my computer. Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.11.45.5) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
– user1927896
Nov 19 at 13:43
Then maybe shorthands likes
andS
cannot be used in character classes in your flavor of C++. In any case, your first regex given is a suitable workaround. But +1 to your good question.
– Tim Biegeleisen
Nov 19 at 13:47
I test the code on Mac, Ubuntu and Windows. It works as expected on Ubuntu and Windows. So I guess s and S cannot be used in character classes under Apple LLVM or it maybe a bug. I am not sure.
– user1927896
Nov 19 at 14:19
1
yes, i agree with you. the issue is not the os. I guess the issue is compiler.
– user1927896
Nov 19 at 14:24
|
show 2 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have the code below this:
#include <string>
#include <regex>
int main(int argc, char const *argv) {
std::string s = "_apple_";
std::regex r1("_(\s|\S)+_");
std::regex r2("_[\s\S]+_");
std::regex r3("_.+_");
std::regex r4("_[pale]+_");
std::smatch sm;
printf("r1:%d r2:%d r3:%d r4:%dn",
std::regex_match(s, sm, r1),
std::regex_match(s, sm, r2),
std::regex_match(s, sm, r3),
std::regex_match(s, sm, r4));
return 0;
}
output:r1:1 r2:0 r3:1 r4:1
I can not understand why r2 is not match?
My environment is:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin.
regex c++11
I have the code below this:
#include <string>
#include <regex>
int main(int argc, char const *argv) {
std::string s = "_apple_";
std::regex r1("_(\s|\S)+_");
std::regex r2("_[\s\S]+_");
std::regex r3("_.+_");
std::regex r4("_[pale]+_");
std::smatch sm;
printf("r1:%d r2:%d r3:%d r4:%dn",
std::regex_match(s, sm, r1),
std::regex_match(s, sm, r2),
std::regex_match(s, sm, r3),
std::regex_match(s, sm, r4));
return 0;
}
output:r1:1 r2:0 r3:1 r4:1
I can not understand why r2 is not match?
My environment is:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin.
regex c++11
regex c++11
edited Nov 19 at 13:51
asked Nov 19 at 13:34
user1927896
62
62
Interesting. On a GCC compiler, your code is working as expected.
– Tim Biegeleisen
Nov 19 at 13:40
but it does not work on my computer. Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.11.45.5) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
– user1927896
Nov 19 at 13:43
Then maybe shorthands likes
andS
cannot be used in character classes in your flavor of C++. In any case, your first regex given is a suitable workaround. But +1 to your good question.
– Tim Biegeleisen
Nov 19 at 13:47
I test the code on Mac, Ubuntu and Windows. It works as expected on Ubuntu and Windows. So I guess s and S cannot be used in character classes under Apple LLVM or it maybe a bug. I am not sure.
– user1927896
Nov 19 at 14:19
1
yes, i agree with you. the issue is not the os. I guess the issue is compiler.
– user1927896
Nov 19 at 14:24
|
show 2 more comments
Interesting. On a GCC compiler, your code is working as expected.
– Tim Biegeleisen
Nov 19 at 13:40
but it does not work on my computer. Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.11.45.5) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
– user1927896
Nov 19 at 13:43
Then maybe shorthands likes
andS
cannot be used in character classes in your flavor of C++. In any case, your first regex given is a suitable workaround. But +1 to your good question.
– Tim Biegeleisen
Nov 19 at 13:47
I test the code on Mac, Ubuntu and Windows. It works as expected on Ubuntu and Windows. So I guess s and S cannot be used in character classes under Apple LLVM or it maybe a bug. I am not sure.
– user1927896
Nov 19 at 14:19
1
yes, i agree with you. the issue is not the os. I guess the issue is compiler.
– user1927896
Nov 19 at 14:24
Interesting. On a GCC compiler, your code is working as expected.
– Tim Biegeleisen
Nov 19 at 13:40
Interesting. On a GCC compiler, your code is working as expected.
– Tim Biegeleisen
Nov 19 at 13:40
but it does not work on my computer. Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.11.45.5) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
– user1927896
Nov 19 at 13:43
but it does not work on my computer. Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.11.45.5) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
– user1927896
Nov 19 at 13:43
Then maybe shorthands like
s
and S
cannot be used in character classes in your flavor of C++. In any case, your first regex given is a suitable workaround. But +1 to your good question.– Tim Biegeleisen
Nov 19 at 13:47
Then maybe shorthands like
s
and S
cannot be used in character classes in your flavor of C++. In any case, your first regex given is a suitable workaround. But +1 to your good question.– Tim Biegeleisen
Nov 19 at 13:47
I test the code on Mac, Ubuntu and Windows. It works as expected on Ubuntu and Windows. So I guess s and S cannot be used in character classes under Apple LLVM or it maybe a bug. I am not sure.
– user1927896
Nov 19 at 14:19
I test the code on Mac, Ubuntu and Windows. It works as expected on Ubuntu and Windows. So I guess s and S cannot be used in character classes under Apple LLVM or it maybe a bug. I am not sure.
– user1927896
Nov 19 at 14:19
1
1
yes, i agree with you. the issue is not the os. I guess the issue is compiler.
– user1927896
Nov 19 at 14:24
yes, i agree with you. the issue is not the os. I guess the issue is compiler.
– user1927896
Nov 19 at 14:24
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
The clang regex flavor is POSIX ERE acc. to clang-format regex syntax reference. In POSIX bracket expressions, the usual regex escape sequences, like s
, d
, w
, and even ]
, are not supported.
The [sS]
is the same as [\sS]
, and matches a backslash, s
and S
chars.
However, in POSIX regex standard, .
matches any chars including line break chars thus there is no need using [sS]
workaround.
but, on a online clang compiler, the code is working as expected. I am sorry i can not find the compiler as the same as my computer. On my computer, the compiler is Apple LLVM version 10.0.0 (clang-1000.11.45.5)
– user1927896
Nov 20 at 2:04
@user1927896 Your is POSIX for sure judging by the behavior. Check here.
– Wiktor Stribiżew
Nov 20 at 6:12
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The clang regex flavor is POSIX ERE acc. to clang-format regex syntax reference. In POSIX bracket expressions, the usual regex escape sequences, like s
, d
, w
, and even ]
, are not supported.
The [sS]
is the same as [\sS]
, and matches a backslash, s
and S
chars.
However, in POSIX regex standard, .
matches any chars including line break chars thus there is no need using [sS]
workaround.
but, on a online clang compiler, the code is working as expected. I am sorry i can not find the compiler as the same as my computer. On my computer, the compiler is Apple LLVM version 10.0.0 (clang-1000.11.45.5)
– user1927896
Nov 20 at 2:04
@user1927896 Your is POSIX for sure judging by the behavior. Check here.
– Wiktor Stribiżew
Nov 20 at 6:12
add a comment |
up vote
0
down vote
The clang regex flavor is POSIX ERE acc. to clang-format regex syntax reference. In POSIX bracket expressions, the usual regex escape sequences, like s
, d
, w
, and even ]
, are not supported.
The [sS]
is the same as [\sS]
, and matches a backslash, s
and S
chars.
However, in POSIX regex standard, .
matches any chars including line break chars thus there is no need using [sS]
workaround.
but, on a online clang compiler, the code is working as expected. I am sorry i can not find the compiler as the same as my computer. On my computer, the compiler is Apple LLVM version 10.0.0 (clang-1000.11.45.5)
– user1927896
Nov 20 at 2:04
@user1927896 Your is POSIX for sure judging by the behavior. Check here.
– Wiktor Stribiżew
Nov 20 at 6:12
add a comment |
up vote
0
down vote
up vote
0
down vote
The clang regex flavor is POSIX ERE acc. to clang-format regex syntax reference. In POSIX bracket expressions, the usual regex escape sequences, like s
, d
, w
, and even ]
, are not supported.
The [sS]
is the same as [\sS]
, and matches a backslash, s
and S
chars.
However, in POSIX regex standard, .
matches any chars including line break chars thus there is no need using [sS]
workaround.
The clang regex flavor is POSIX ERE acc. to clang-format regex syntax reference. In POSIX bracket expressions, the usual regex escape sequences, like s
, d
, w
, and even ]
, are not supported.
The [sS]
is the same as [\sS]
, and matches a backslash, s
and S
chars.
However, in POSIX regex standard, .
matches any chars including line break chars thus there is no need using [sS]
workaround.
answered Nov 19 at 21:50
Wiktor Stribiżew
304k16123199
304k16123199
but, on a online clang compiler, the code is working as expected. I am sorry i can not find the compiler as the same as my computer. On my computer, the compiler is Apple LLVM version 10.0.0 (clang-1000.11.45.5)
– user1927896
Nov 20 at 2:04
@user1927896 Your is POSIX for sure judging by the behavior. Check here.
– Wiktor Stribiżew
Nov 20 at 6:12
add a comment |
but, on a online clang compiler, the code is working as expected. I am sorry i can not find the compiler as the same as my computer. On my computer, the compiler is Apple LLVM version 10.0.0 (clang-1000.11.45.5)
– user1927896
Nov 20 at 2:04
@user1927896 Your is POSIX for sure judging by the behavior. Check here.
– Wiktor Stribiżew
Nov 20 at 6:12
but, on a online clang compiler, the code is working as expected. I am sorry i can not find the compiler as the same as my computer. On my computer, the compiler is Apple LLVM version 10.0.0 (clang-1000.11.45.5)
– user1927896
Nov 20 at 2:04
but, on a online clang compiler, the code is working as expected. I am sorry i can not find the compiler as the same as my computer. On my computer, the compiler is Apple LLVM version 10.0.0 (clang-1000.11.45.5)
– user1927896
Nov 20 at 2:04
@user1927896 Your is POSIX for sure judging by the behavior. Check here.
– Wiktor Stribiżew
Nov 20 at 6:12
@user1927896 Your is POSIX for sure judging by the behavior. Check here.
– Wiktor Stribiżew
Nov 20 at 6:12
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375798%2fwhy-does-s-s-not-working-in-c11s-regex%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Interesting. On a GCC compiler, your code is working as expected.
– Tim Biegeleisen
Nov 19 at 13:40
but it does not work on my computer. Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.11.45.5) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
– user1927896
Nov 19 at 13:43
Then maybe shorthands like
s
andS
cannot be used in character classes in your flavor of C++. In any case, your first regex given is a suitable workaround. But +1 to your good question.– Tim Biegeleisen
Nov 19 at 13:47
I test the code on Mac, Ubuntu and Windows. It works as expected on Ubuntu and Windows. So I guess s and S cannot be used in character classes under Apple LLVM or it maybe a bug. I am not sure.
– user1927896
Nov 19 at 14:19
1
yes, i agree with you. the issue is not the os. I guess the issue is compiler.
– user1927896
Nov 19 at 14:24