eliasdabbas / advertools

advertools - online marketing productivity and analysis tools
https://advertools.readthedocs.io
MIT License
1.12k stars 210 forks source link

Instagram Mentions Allows Periods #343

Open juanlazarde opened 6 months ago

juanlazarde commented 6 months ago

Hi Elias,

Comments on Instagram that include mentions with periods are currently truncated on advertools.__version__ = 0.14.2. Example: @elias.dabbas -> [@elias]

I propose adding adding a . to the MENTIONS in the REGEX module.

MENTION = re.compile(
    r"""(?i)     # case-insensitive
    (?<!\w)      # word character doesn't precede mention
    ([@@]       # either of two @ signs
    [a-z0-9_.]+)  # A to Z, numbers and underscores AND PERIODS only
    \b           # end with a word boundary
    """, re.VERBOSE)

This change works for me, but I haven't tested edge cases or other social media platforms.

eliasdabbas commented 6 months ago

Good point!

The edge case I can think of is someone mentioning someone at the end of a sentence and not adding a space at the end:

"Nice post by @username.Check it out" --> [@username.Check]

If the period is followed by a space then we can make sure the regex doesn't match it, only if word characters follow it.

Are there other characters that need to be handled?

Thanks for reporting.