mrhhsg opened a new pull request, #68358:
URL: https://github.com/apache/doris/pull/68358

   ### What problem does this PR solve?
   
   Issue Number: None
   
   Problem Summary:
   
   With `enable_extended_regex = true`, patterns that RE2 rejects (lookahead,
   lookbehind, ...) are compiled with Boost.Regex. In the Boost branch of
   `RegexpExtractEngine::match_all_and_extract`, a zero-width match advanced the
   next search from the *old* search start plus one instead of from the position
   that was actually matched. When the first search started at offset 0 and the
   zero-width match was found at offset 1, the next search started at offset 1 
and
   hit the same position again, so the same capture was extracted twice.
   
   ```sql
   SET enable_extended_regex = true;
   SELECT regexp_extract_all('ba', '(?=(a))');        -- before: ['a','a']
   SELECT regexp_extract_all_array('ba', '(?=(a))');  -- before: ["a", "a"]
   ```
   
   The lookahead can only match once, at the last position, so both functions 
must
   return a single `a`.
   
   Fix: after a zero-width match, continue the search from `matches[0].second + 
1`
   (the byte after the matched position) and stop when the match sits at the 
end of
   the input. Non-zero-width matches keep advancing past the whole match as 
before.
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Test:
       - Unit Test: `FunctionLikeTest.regexp_extract_all_boost_zero_width_match`
       - Regression test: `test_string_function_regexp` (new zero-width cases 
for
         `regexp_extract_all` and `regexp_extract_all_array`)
   - Behavior changed: No
   - Does this need documentation: No
   
   https://claude.ai/code/session_015YrLgWt4YQutuPrJpARn3s
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to