Monday, March 10, 2025

Regex obfuscate email

 Use this code in C# to obfuscate email using regex

// Online C# Editor for free

// Write, Edit and Run your C# code using C# Online Compiler


using System;

using System.Text.RegularExpressions;

public class HelloWorld

{

    public static void Main(string[] args)

    {

        Console.WriteLine ("Try programiz.pro");

        string _PATTERN = @"(?<=.{4}).(?=[^@]*?@)|(?:(?<=@.)|(?!^)\G(?=[^@]*$))(.)(?=.*\.)[a-zA-Z0-9]";

 

        string s = "john.travolta12+-3878787@gmail.com";

      string replacement = "*";

      

      if (!s.Contains("@"))

        Console.WriteLine( new String('*', s.Length));

      if (s.Split('@')[0].Length < 4) 

        Console.WriteLine( @"*@*.*"); 


        string result = Regex.Replace(s, _PATTERN, replacement);

      Console.WriteLine(result);

    

    }

}

Regex obfuscate email

 Use this code in C# to obfuscate email using regex // Online C# Editor for free // Write, Edit and Run your C# code using C# Online Compile...