Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda