Why does “[\s\S]” not working in C++11's regex












1














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.










share|improve this question
























  • Interesting. On a GCC compiler, your code is working as expected.
    – Tim Biegeleisen
    Nov 19 '18 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 '18 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 '18 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 '18 at 14:19








  • 1




    yes, i agree with you. the issue is not the os. I guess the issue is compiler.
    – user1927896
    Nov 19 '18 at 14:24
















1














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.










share|improve this question
























  • Interesting. On a GCC compiler, your code is working as expected.
    – Tim Biegeleisen
    Nov 19 '18 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 '18 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 '18 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 '18 at 14:19








  • 1




    yes, i agree with you. the issue is not the os. I guess the issue is compiler.
    – user1927896
    Nov 19 '18 at 14:24














1












1








1







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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 13:51

























asked Nov 19 '18 at 13:34









user1927896

62




62












  • Interesting. On a GCC compiler, your code is working as expected.
    – Tim Biegeleisen
    Nov 19 '18 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 '18 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 '18 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 '18 at 14:19








  • 1




    yes, i agree with you. the issue is not the os. I guess the issue is compiler.
    – user1927896
    Nov 19 '18 at 14:24


















  • Interesting. On a GCC compiler, your code is working as expected.
    – Tim Biegeleisen
    Nov 19 '18 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 '18 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 '18 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 '18 at 14:19








  • 1




    yes, i agree with you. the issue is not the os. I guess the issue is compiler.
    – user1927896
    Nov 19 '18 at 14:24
















Interesting. On a GCC compiler, your code is working as expected.
– Tim Biegeleisen
Nov 19 '18 at 13:40




Interesting. On a GCC compiler, your code is working as expected.
– Tim Biegeleisen
Nov 19 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 14:24




yes, i agree with you. the issue is not the os. I guess the issue is compiler.
– user1927896
Nov 19 '18 at 14:24












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer





















  • 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 '18 at 2:04












  • @user1927896 Your is POSIX for sure judging by the behavior. Check here.
    – Wiktor Stribiżew
    Nov 20 '18 at 6:12











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














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.






share|improve this answer





















  • 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 '18 at 2:04












  • @user1927896 Your is POSIX for sure judging by the behavior. Check here.
    – Wiktor Stribiżew
    Nov 20 '18 at 6:12
















0














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.






share|improve this answer





















  • 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 '18 at 2:04












  • @user1927896 Your is POSIX for sure judging by the behavior. Check here.
    – Wiktor Stribiżew
    Nov 20 '18 at 6:12














0












0








0






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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 21:50









Wiktor Stribiżew

308k16126202




308k16126202












  • 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 '18 at 2:04












  • @user1927896 Your is POSIX for sure judging by the behavior. Check here.
    – Wiktor Stribiżew
    Nov 20 '18 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 '18 at 2:04












  • @user1927896 Your is POSIX for sure judging by the behavior. Check here.
    – Wiktor Stribiżew
    Nov 20 '18 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 '18 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 '18 at 2:04














@user1927896 Your is POSIX for sure judging by the behavior. Check here.
– Wiktor Stribiżew
Nov 20 '18 at 6:12




@user1927896 Your is POSIX for sure judging by the behavior. Check here.
– Wiktor Stribiżew
Nov 20 '18 at 6:12


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules