Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8474685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:41:37+00:00 2026-06-10T17:41:37+00:00

Possible Duplicate: regexp to partly hide email? I’m currently writing a script that hides

  • 0

Possible Duplicate:
regexp to partly hide email?

I’m currently writing a script that hides an email address (so test@domain.com becomes t~~~@~~~~~~.com).

Whilst following the instructions on this question – regexp to partly hide email? – I have managed to get it to display t~~~@domain.com, but am having trouble removing the “domain”.

Here is what I have so far (assume $row->email is “test@domain.com”):-

$string = preg_replace("(?<=.).(?=.*@)","~", $row->email);
$string = preg_replace("(?<=@).[a-zA-Z0-9]*","~", $string);

However, all it returns is t~~~@~omain.com

I’m baffled as to how to get the rest of the domain bit. Ideas?

IDEALLY if anybody can provide a solution so it becomes t~~~@d~~~~~~.com, that’d be super.

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:41:38+00:00Added an answer on June 10, 2026 at 5:41 pm

    It is ..

    • matching (and skipping) "@" and then;
    • matching . (any character: i.e. the "d" in "domain") and then;
    • matching 0 (zero) of the following character class, which is the minimum it needed to match the supplied regular expression.

    That is, the first and only the first character after the @ was matched and replaced with ~.

    The following

    (?<=@.)[a-zA-Z0-9-]*(?=(?:[.]|$))
    

    forces the character class to match to the first "." (period, as in ".com") or end-of-input.

    Note that the . is moved inside of the (?<=@.)-look-behind clause which causes it to skip the first letter after the "@". I have also added a hyphen ("-") to the character class as they are valid (and not terribly uncommon) in domain names.

    In addition, not all email addresses are in the trivial "a@b.c" form and Internationalized Domain Names (or IDN) can be represented locally in a non-punycode form when not transmitted (e.g. not used in a restricting context), but that is another topic. (It may be more appropriate to replace [a-zA-Z0-9-]* with [^.]* due to IDN without further specification.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Regexp recognition of email address hard? Hi, I would like to implement
Possible Duplicate: Interesting test of Javascript RegExp Regular expression test can't decide between true
Possible Duplicate: Regexp for extracting a mailto: address I want to fetch the emails
Possible Duplicate: regexp with russian lang I have a regular expression that filters out
Possible Duplicate: typeof for RegExp I have a routine that is testing to see
Possible Duplicate: php regexp: remove all attributes from an html tag $input = '<div
Possible Duplicate: PHP REGEX: Get domain from URL I am working on a project
Possible Duplicate: RegEx to make sure that the string contains at least one lower
Possible Duplicate: Modify regex to validate email? $email = $_POST[email]; if(preg_match([@{1}],$email)) echo There is
Possible Duplicate: Why RegExp with global flag in Javascript give wrong results? var reg1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.