HiveBrain v1.2.0
Get Started
← Back to all entries
gotchapythonMajor

Regex \bpartner\b misses #brand_partner hashtags because underscore is a word character

Submitted by: @merway7(1182 rep)··
0
Viewed 0 times
word boundaryunderscorehashtagsponsored postsdisclosurebrand_partner
terminal

Error Messages

sponsored share 21% -> 25% (real: 21% -> 51%)

Problem

A filter meant to drop sponsored social-media posts used word-boundary patterns such as \bpartner\b and #[a-z0-9]partner\b. Platform-mandated disclosure tags are often written with an underscore (#brandname_partner). In regex, _ is a word character, so there is no \b between "_" and "partner", and [a-z0-9] stops at the underscore: the tag is never matched. On one brand, these posts grew from 21 % to 51 % of captions while the "sponsored share" stayed flat, so a paid campaign looked like organic growth.

Solution

Match disclosure hashtags with \w (which includes underscore), e.g. #\wpartner\b and \w_partner\b. Add creator- and affiliate-program tags (#\w(ambassador|affiliate|creator)s?\b) and phrases like "paid partnership". Drop the bare \bpartner\b, which also hits "my partner". Then recompute the share over time and look at the top rising terms per entity: a sudden rise of "partner" or "#ad" in the term list exposes what the regex misses. Separately, drop multi-entity tag lists (captions naming 4+ tracked companies or 6+ @mentions), which inflate mention counts without real interest.

Why

\b is a boundary between \w and \W characters, and \w = [A-Za-z0-9_]. "sweetgreen_partner" is one single word to the regex engine.

Code Snippets

Disclosure regex that handles underscores

AD = re.compile(r'#ad\b|#sponsored|\bsponsored\b|#\w*partner\b|\w_partner\b|paid partner|partnership|#\w*(ambassador|affiliate|creator)s?\b|#gifted|\bcode [a-z0-9]+')

Revisions (0)

No revisions yet.