æ£è¦è¡¨ç¾ã§ [a-[:alpha:]ï¼½ ã®æå³ã£ã¦?
C++11 ã®ä»æ§ã«å¯¾ããçå
C++11 ã®æ£è¦è¡¨ç¾ (std::regex_constants::ECMAScript æ) ã®ä»æ§ã¯ ECMA-262 ã®ææ³ã次ã®ããã«å¾®å¦ã«å¤æ´ãããã®ã¨ãªã£ã¦ãã¾ãã
ClassAtom ::
-
ClassAtomNoDash
ClassAtomExClass
ClassAtomCollatingElement
ClassAtomEquivalence
ClassAtomExClass ::
[: ClassName :]
ClassAtomCollatingElement ::
[. ClassName .]
ClassAtomEquivalence ::
[= ClassName =]
ClassName ::
ClassNameCharacter
ClassNameCharacter ClassName
ClassNameCharacter ::
SourceCharacter but not one of "." "=" ":"
(ãã©ãã n3337.pdf ãã)
ãã㦠ECMA-262 ã®æ£è¦è¡¨ç¾ã®æåã¯ã©ã¹å¨ãã®ææ³ã¯ã ããã以ä¸ã®ãããªæãã«ãªã£ã¦ãã¾ãã
CharacterClass ::
[ [lookahead ∉ {^}] ClassRanges ]
[ ^ ClassRanges ]
ClassRanges ::
[empty]
NonemptyClassRanges
NonemptyClassRanges ::
ClassAtom
ClassAtom NonemptyClassRangesNoDash
ClassAtom - ClassAtom ClassRanges
NonemptyClassRangesNoDash ::
ClassAtom
ClassAtomNoDash NonemptyClassRangesNoDash
ClassAtomNoDash - ClassAtom ClassRanges
ClassAtom :: (ãã㯠C++11 ã®ä»æ§ã§å¤æ´ããã)
-
ClassAtomNoDash
ClassAtomNoDash ::
SourceCharacter but not one of \ or ] or -
\ ClassEscape
ClassEscape ::
DecimalEscape
b
CharacterEscape
CharacterClassEscape
(Standard ECMA-262 ãã)
ããã§ã強調ããé¨åãã¤ã¾ã以ä¸ã®é¨å
ClassAtom ::
ClassAtomExClass
NonemptyClassRanges ::
ClassAtom - ClassAtom ClassRanges
NonemptyClassRangesNoDash ::
ClassAtomNoDash - ClassAtom ClassRanges
ãç´ ç´ã«è§£éããã¨ãä¾ãã°æ¬¡ã®ãããªæ£è¦è¡¨ç¾ã¯ææ³ä¸æ£ããã¨ãããã¨ã«ãªãã¾ãã
[a-[:alpha:]] [[:alpha:]-a] [[:alpha:]-[:alpha:]]
ææ³ä¸ã¯æ£ããã¨ãã£ã¦ããä½ã表ç¾ãã¦ããã®ãæå³ããããããã¾ããã
ç¾å®ã®å®è£ ã§ã¯?
ä¾ãã°ãBoost C++ Libraries ã§ã¯ãã¹ãã±ã¼ã¹ (test_sets.cpp) å ã§ã以ä¸ã®ãããªãã¹ãããã¦ããã
TEST_INVALID_REGEX("[a-[:alpha:]]", boost::regex::extended);
åé¡ã¨ãªãæ£è¦è¡¨ç¾ãè¨è¿°ã§ããªããã¨ã確ããã¦ãã¾ãã
ã¾ããOS X Mountain Lion ã® clang-425.0.28 ã§ã¯ã
#include <regex> #include <iostream> int main() { std::locale::global(std::locale("C")); std::regex re("[a-[:alpha:]]"); std::cout << std::boolalpha << regex_match("a", re) << std::endl; std::cout << std::boolalpha << regex_match("b", re) << std::endl; return 0; }
ä¸è¨ã®ã½ã¼ã¹ã -std=c++11 -stdlib=libc++ ã§ã³ã³ãã¤ã«ãã¦å®è¡ããã¨
ãåºåããã¾ãããªã«ãèµ·ãã£ãã®ããããããã¾ããã
true
false
ã¾ããVisual Studio 2012 Express ã§ã¯ä¸è¨ã®ã½ã¼ã¹ãå®è¡ãã㨠std::regex ã®ã³ã³ã¹ãã©ã¯ã¿å 㧠std::regex_error ä¾å¤ã .code() == std::regex_constants::error_range 㧠throw ããã¾ãã
ã¾ã¨ã
ã¨ããããã§ããã®åé¡ã¯ C++11 ã®ä»æ§ã®ééãã¨ãã¦è§£éããã®ãè¯ãã¨æãã¾ãã