diff --git a/include/boost/regex/v4/basic_regex_parser.hpp b/include/boost/regex/v4/basic_regex_parser.hpp index 8889db7e..ce4abf7c 100644 --- a/include/boost/regex/v4/basic_regex_parser.hpp +++ b/include/boost/regex/v4/basic_regex_parser.hpp @@ -971,7 +971,13 @@ bool basic_regex_parser::parse_repeat(std::size_t low, std::size_ ) { // OK we have a perl or emacs regex, check for a '?': - if(this->m_traits.syntax_type(*m_position) == regex_constants::syntax_question) + if ((this->flags() & (regbase::main_option_type | regbase::mod_x | regbase::no_perl_ex)) == regbase::mod_x) + { + // whitespace skip: + while ((m_position != m_end) && this->m_traits.isctype(*m_position, this->m_mask_space)) + ++m_position; + } + if((m_position != m_end) && (this->m_traits.syntax_type(*m_position) == regex_constants::syntax_question)) { greedy = false; ++m_position; @@ -1064,6 +1070,12 @@ bool basic_regex_parser::parse_repeat(std::size_t low, std::size_ // Check for illegal following quantifier, we have to do this here, because // the extra states we insert below circumvents our usual error checking :-( // + if ((this->flags() & (regbase::main_option_type | regbase::mod_x | regbase::no_perl_ex)) == regbase::mod_x) + { + // whitespace skip: + while ((m_position != m_end) && this->m_traits.isctype(*m_position, this->m_mask_space)) + ++m_position; + } switch(this->m_traits.syntax_type(*m_position)) { case regex_constants::syntax_star: diff --git a/test/regress/test_simple_repeats.cpp b/test/regress/test_simple_repeats.cpp index 3fbed7a4..1a73fde6 100644 --- a/test/regress/test_simple_repeats.cpp +++ b/test/regress/test_simple_repeats.cpp @@ -486,5 +486,15 @@ void test_pocessive_repeats() TEST_INVALID_REGEX("\\d*++", perl); TEST_INVALID_REGEX("\\d?++", perl); TEST_INVALID_REGEX("\\d{1,2}++", perl); + + TEST_REGEX_SEARCH("(ab +)", perl|mod_x, "abbb", match_default, make_array(0, 4, 0, 4, -2, -2)); + TEST_REGEX_SEARCH("(ab +?)", perl | mod_x, "abbb", match_default, make_array(0, 2, 0, 2, -2, -2)); + TEST_REGEX_SEARCH("(ab + ?)", perl | mod_x, "abbb", match_default, make_array(0, 2, 0, 2, -2, -2)); + TEST_REGEX_SEARCH("(ab ++)", perl | mod_x, "abbb", match_default, make_array(0, 4, 0, 4, -2, -2)); + TEST_REGEX_SEARCH("(ab + +)", perl | mod_x, "abbb", match_default, make_array(0, 4, 0, 4, -2, -2)); + TEST_INVALID_REGEX("(ab + ++)", perl | mod_x); + TEST_INVALID_REGEX("(ab + + +)", perl | mod_x); + TEST_INVALID_REGEX("(ab + + ?)", perl | mod_x); + }