Skip to main content

Stripping contact details from user text before publishing it

Six regular expressions, one line-level rule, and the honest list of things they still get wrong

Updated 8 min readMarkdown
Stripping contact details from user text before publishing it

Some of the text on our site is written by people we do not control. Employers paste job descriptions into a form, and candidates fill in profiles. Both end up on public pages that search engines and AI crawlers read within days.

Two kinds of text kept leaking through. Employers wrote "send your CV to hr@..." or "DM @recruiter in Telegram", which takes the whole conversation off the platform. And candidates put their phone number into the "about" field, which defeats the point of an anonymous profile.

The fix looked like a one-liner: find contacts, delete them. It turned into a small module with a few rules that took longer to get right than the regexes themselves.

What counts as a contact

We started with a list of patterns we actually saw in submitted text, not a list of everything that could be a contact. Six patterns covered almost all of it:

import re

EMAIL     = r"[\w.+-]+@[\w-]+(?:\.[\w-]+)+"
TG_LINK   = r"(?:https?://)?(?:www\.)?(?:t\.me|telegram\.me)/[\w+/-]+"
MESSENGER = r"(?:https?://)?(?:wa\.me|api\.whatsapp\.com|viber\.click)/[\w?=&+/-]+"
LINKEDIN  = r"(?:https?://)?(?:[a-z]{2,3}\.)?linkedin\.com/in/[\w%-]+/?"
HANDLE    = r"(?<![\w.@])@[A-Za-z][A-Za-z0-9_]{4,31}\b"
PHONE     = r"(?<![\w+])\+\d[\d\s().-]{8,17}\d"

CONTACT_RE = re.compile("|".join(
    (EMAIL, TG_LINK, MESSENGER, LINKEDIN, HANDLE, PHONE)), re.I)

Each one has a detail that came from a false positive or a miss.

The handle pattern requires at least five characters after the @, which is the minimum Telegram allows. That single rule means @team or @here, which people do write in job descriptions about their workflow, survive. The lookbehind stops it from matching the middle of an email address, which the email pattern has already claimed.

The phone pattern in job texts requires a leading +. Descriptions are full of numbers that look like phones once you allow spaces and dashes: salary ranges, headcounts, version strings, "1 000 000 monthly users". An international prefix is the one thing a phone number has and a salary does not.

The LinkedIn pattern only matches /in/, personal profiles. A link to a company page is fine. A link to the recruiter's own profile is a contact.

Profiles need a greedier pattern

Candidate profiles use a different, older pattern, and it is deliberately less careful:

PII_RE = re.compile(
    r"(\+?\d[\d\s().-]{8,}\d)"              # phone, plus is optional
    r"|([\w.+-]+@[\w-]+\.[\w.]+)"           # email
    r"|(https?://\S+|www\.\S+|t\.me/\S+)",  # any link at all
    re.I)

Here the plus is optional and any URL goes. A profile is supposed to be anonymous until an employer unlocks the contacts, so a false positive costs us a lost number in a summary. A false negative publishes someone's phone. We accept the first to avoid the second.

The same text type, two tolerances. Choosing the direction you want to be wrong in, per field, was the most useful decision in the whole module.

Deleting the match is not enough

The first version did CONTACT_RE.sub("", text). The output was technically clean and practically broken:

Interested? Write to us in Telegram:
Send your CV to

Lines like these are worse than the contact. They tell the reader something was removed, and they make the employer's post look sloppy. So the function works line by line, and for each line that had a contact it asks one question: is there anything left worth keeping?

LEAD = re.compile(
    r"(?:write|send|contact\w*|dm|cv|telegram|tg|e-?mail|whatsapp|viber)"
    r"\b[^\n]{0,40}$", re.I)

def strip_line(line: str) -> str | None:
    if not CONTACT_RE.search(line):
        return line
    rest = CONTACT_RE.sub("", line)
    # drop the "write to us at" tail, then count real characters
    meaningful = re.sub(r"\W", "", LEAD.sub("", rest))
    if len(meaningful) >= 25:
        return re.sub(r"[ \t]{2,}", " ", rest).rstrip()
    return None    # the whole line was about the contact

The LEAD pattern describes the tail of a sentence that only makes sense with a contact after it: "write to", "send your CV", "Telegram вАФ". It is stripped only for the length check, not from the output. The real list also includes the Russian and Ukrainian forms, because most of our employers write in those languages.

Twenty-five word characters is the threshold. Below it the line was a call to action and goes away completely. Above it the line had real content, so only the contact itself is removed and double spaces are squeezed.

After the loop, runs of three or more newlines collapse into one blank line, so a deleted contact block does not leave a hole in the layout.

Keep what you remove, when it is useful

Removing an employer's Telegram from the public text is right. Throwing it away is not: it is exactly the channel our team wants for talking to that employer later.

So the function returns two things, the clean text and the first Telegram handle it found:

TG_IN = re.compile(
    r"(?:t\.me/|telegram\.me/|(?<![\w.@])@)([A-Za-z][A-Za-z0-9_]{4,31})\b",
    re.I)

def strip_contacts(text: str) -> tuple[str, str]:
    tg, out = "", []
    for line in text.replace("\r\n", "\n").split("\n"):
        for hit in CONTACT_RE.findall(line):
            m = TG_IN.search(hit)
            if m and not tg:
                tg = "@" + m.group(1)
        kept = strip_line(line)
        if kept is not None:
            out.append(kept)
    clean = re.sub(r"\n{3,}", "\n\n", "\n".join(out)).strip()
    return clean, tg

The caller saves the handle to the employer's account, but only if the account does not have one yet. We never overwrite a value the employer typed into their settings with one we guessed from a description.

Where it runs

There are three write paths for an employer's job: posting, editing and approval by a moderator. The function is called on all three. Running it only at posting time was the first bug: an employer would post a clean text, then edit the contact back in an hour later.

Approval is the third gate because moderation can also change text, and because a job can sit in the queue while the rules change. Whatever reaches the public page has passed the current version of the filter.

def hide_job_contacts(job, owner=None) -> bool:
    if not job.owner_id:
        return False          # imported jobs are left as they are
    clean, tg = strip_contacts(job.description or "")
    changed = clean != (job.description or "").strip()
    if changed:
        job.description = clean
    if tg and owner is not None and not owner.telegram:
        owner.telegram = tg
    return changed

Note the early return. Jobs we import from other sources keep their text untouched, because there the apply flow goes to the original posting and the contacts belong to it. The filter is a rule about our own submissions, not a general sanitiser.

The function returns whether it changed anything. That boolean is what lets a caller tell the employer "we removed contact details, candidates apply through the site", instead of silently editing their text.

What it still gets wrong

Running it on real and made-up lines shows the edges clearly:

"Send your CV to jobs@example.com"        -> ""             (line dropped)
"Telegram: @hr_example"                   -> ""             tg="@hr_example"
"Ping @team in Slack"                     -> unchanged      (too short for a handle)
"Version 2.10.3.4 released"               -> unchanged      (no plus, not a phone)
"Salary 3000-4000 EUR, call +44 20 ..."   -> ""             (line dropped)

The last one is a real loss. The line had useful information, but after removing the phone and the "call" tail only eighteen characters remain, so the whole line goes. The salary disappears with the phone. We have kept this behaviour so far, because the alternative ("Salary 3000-4000 EUR, call") reads worse, but it is a trade-off and not a feature.

The regexes also cannot see contacts written to dodge them: "hr at company dot com", a handle with spaces, a phone spelled out in words. We deliberately did not try to cover these. If someone does it, it is a moderation problem, not a regex problem. Escalating a pattern war against a determined user is a game you lose.

Names are the other gap. No pattern finds "ask for Maria". For candidate profiles we solve it structurally: the public profile has no name field, and the data that feeds it never asks the model for one.

What we learned

  • Collect real examples first. Six patterns from actual submissions beat a long list from a cheat sheet.
  • Pick the direction of error per field. Anonymous profiles should over-delete; job descriptions should keep salaries and version numbers.
  • Delete at the line level, not the match level. A sentence that pointed at a removed contact is noise.
  • Keep what you strip when it has a legitimate use, and never overwrite a value the user set themselves.
  • Run the filter on every write path, including edits and moderation, and tell the user when it changed their text.

We use this at SpinHire, a job board for the iGaming industry, where every job posted directly by an employer goes through it before it is shown.

About the author

  • SpinHire (spinhire.io) is a job board built only for the iGaming industry: casino, sports betting, game studios, affiliates, payments and compliance. We index 6,600+ live roles from 430+ companies every 6 hours and keep the data open: a public jobs API without a key (CC BY 4.0), XML and RSS feeds, and an MCP server for AI assistants. Here we write about building that index, iGaming tech careers and developer salaries.

No comments yet. Be the first to comment.