Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
Is there a regex to mask middle areas of a dynamic alphanumeric string?

I am trying to mask some confidential information which can be any alphanumeric string for ex .

Example 1

Before masking - PMGKJGFWB125 After masking - PMG******125

Example 2

Before masking - 19000 After masking - 1**00

I was trying something like this in C#

Regex.Replace(s, @"\d(?!\d{0,3}$)", "*")

The length of string may vary so we cannot add hardcoded offsets .

Can I get some help on this ?

Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Looks like, roughly roughly, you want to divide your string up into quarters and then star out the middle two quarters

Don't get too technical..

var str = "PMGKJGFWB125".ToCharArray();

for(int x = str.Length/4; x < str.Length*3/4; x++)
  str[x] = '*';

return new string(str);

You can adjust the 4 for different length strings e.g. if your string is 6 or less maybe do 3 instead of 4.. etc

If you want it as LINQ, for a "WTH is that?!" laugh:

(int f, int t) = (str.Length/4, str.Length*3/4);
return string.Concat(str.Select((c,i)=>f<i&&i<t?'*':c)));
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda