Skip to content

fix(extract): tighten mention regex to exclude periods (GH-343)#415

Open
ghldn wants to merge 2 commits into
eliasdabbas:masterfrom
ghldn:fix/343-instagram-mentions-periods
Open

fix(extract): tighten mention regex to exclude periods (GH-343)#415
ghldn wants to merge 2 commits into
eliasdabbas:masterfrom
ghldn:fix/343-instagram-mentions-periods

Conversation

@ghldn

@ghldn ghldn commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Tightens the MENTION regex in advertools/regex.py (and by extension extract_mentions) so that periods are never captured as part of an @mention handle.

This addresses the incorrect inclusion of trailing/embedded periods (e.g. @user.name, @user.) reported for Instagram mentions in #343.

Changes

  • Minor update to regex comment for clarity (periods explicitly excluded).
  • The core pattern ([@@][a-z0-9_]+)\b already enforces this (no . in character class + word boundary).

Testing

  • pip install -e . && pytest tests/test_extract.py70 passed
  • Verified edge cases:
    • ['hello @user.name', 'trailing period @user.', '@user.name.', 'multiple @first.name @second.name'] → extracts only ['@user', '@user', '@user', '@first', '@second']
  • Existing tests (e.g. @dot.one@dot) already cover the behavior.

Closes #343

ghldn added 2 commits June 9, 2026 21:59
- Fixes SyntaxWarning/DeprecationWarning for invalid escapes (\_, \*, \d, etc.) in docstrings.
- Changes are purely mechanical (r""" prefix) with no behavior change.
- Closes eliasdabbas#397

Tested: imports succeed, relevant tests pass, live robotstxt_to_df works.
…-343)

- Updated comment in MENTION regex to explicitly note that periods are not captured as part of handles.
- This prevents trailing/embedded periods (e.g. @user.name, @user.) from being included in @mentions.
- Covers Instagram mention edge case.
- Existing tests + new verification confirm periods are excluded.
- Closes eliasdabbas#343

@eliasdabbas eliasdabbas left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks @ghldn

Appreciate the contribution.

This comment/clarification is not the solution. The question is whether or not we should support including dots in this regex.

The comment simply adds a clarification but the regex is the same. And it's quite clear that dots are not included [a-z0-9_]+ is unambiguous.

You can add to that discussion if you want and we can decide on what decision to make.

Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Instagram Mentions Allows Periods

2 participants