Skip to content

fix: return an empty string when RegexTextExtractor's first group is not part of the match - #13649

Merged
davidsbatista merged 3 commits into
deepset-ai:mainfrom
chrikrah:fix/regex-extractor-unmatched-group
Nov 10, 2026
Merged

davidsbatista merged 3 commits into
deepset-ai:mainfrom
chrikrah:fix/regex-extractor-unmatched-group

Conversation

@chrikrah

@chrikrah chrikrah commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

_extract_from_text returned match.group(1) whenever the pattern had a group, and that is None when the group sits on the other side of an alternation (Score: (\d+)|N/A on "N/A") or is optional and unmatched. The component declares captured_text=str, so it now returns "", the value a failed match already gives. It is the fix from #12896 (gauravch-code), closed at the first-PR limit, and #13500 (xubenqiang), closed today on the unsigned CLA.

How did you test it?

Both patterns from the issue, as one parametrized test.

$ python -m pytest -q test/components/extractors -m "not integration"   # main 811d921, Python 3.12
this branch:                   100 passed, 5 deselected
regex_text_extractor.py reverted:  2 failed, 98 passed   (both new cases: None != "")
$ ruff check && ruff format --check    # ruff 0.16.0, both touched files: clean
$ mypy haystack/components/extractors/regex_text_extractor.py
Success: no issues found in 1 source file   # mypy 2.4.1
# not run: integration tests, the full suite

Notes for the reviewer

A pipeline that tested captured_text is None now sees "", as for no match. I kept "" over group(0) so a caller has one empty value to test for.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue: it already holds the repro.
  • I have added unit tests and updated the docstrings.
  • I've used a conventional commit type for my PR title.
  • I have documented my code.
  • I have added a release note file.
  • I have run pre-commit hooks, as quoted.

@davidsbatista, you added the component in #9879. Is "" right, or should an unmatched group fall back to the whole match?

Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
…not part of the match

Fixes #13484

Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
@chrikrah
chrikrah requested a review from a team as a code owner November 9, 2026 20:41
@chrikrah
chrikrah requested review from bogdankostic and removed request for a team November 9, 2026 20:41
@vercel

vercel Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@chrikrah is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the P3 Low priority, leave it in the backlog label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Hi @chrikrah, thanks for your interest in contributing to Haystack! 🙏

⚠️ Issue #13484 is already being addressed by open pull request(s) #13648. Before opening a PR for an issue, please check whether a PR is already linked to it, and consider contributing to the existing PR instead. We may close duplicate PRs to keep the review queue manageable.

This is an automated message to help us keep the review queue healthy.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/extractors
  regex_text_extractor.py
  haystack/core/pipeline
  pipeline.py
Project Total  

This report was generated by python-coverage-comment-action

@davidsbatista

Copy link
Copy Markdown
Contributor

"" is right. The group captured nothing, and "" is already what a failed match returns, so callers only need one emptiness check. Falling back to group(0) would hand back text the pattern wasn't asked to capture.

I pushed a small follow-up: the run() docstring now mentions this case, and there's a test for the ChatMessage input path. Thanks!

@vercel

vercel Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
haystack-docs Ignored Ignored Preview Nov 10, 2026 8:00am UTC

Request Review

@davidsbatista davidsbatista left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@davidsbatista
davidsbatista merged commit 4c3ea05 into deepset-ai:main Nov 10, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low priority, leave it in the backlog topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RegexTextExtractor returns captured_text None when the capture group is not part of the match

2 participants