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

313
Vistas
Regex to match name prefix

I need regex conditions that matches any string satisfying the following condition:

  1. String starts with the prefix Mr., Mrs., Ms., Dr., or Er.

I tried /(?<!prefix )Mr.[a-zA-Z]/ so far, but it didn't work.

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

0

(Mr|Mrs|Ms|Dr|Er)\.[a-zA-Z]+

Explanation:

  • (Mr|Mrs|Ms|Dr|Er) - uses grouping and alternation to match any of the following: Mr, Mrs, Ms, Dr, Er

  • \. - matches the literal . character

  • [a-zA-Z]+ - matches one or more occurence of an uppercase/lowercase letter.

const regex = /(Mr|Mrs|Ms|Dr|Er)\.[a-zA-Z]+/;

function validate(str){
  console.log(`${str} matches regex? ${regex.test(str)}`)
}

validate("Mr.John")
validate("Mrs.John")
validate("Ms.John")
validate("Dr.John")
validate("Er.John")
validate("Spectric.Spectric")

about 4 years ago · Juan Pablo Isaza Denunciar

0

To match all variants you can write the pattern as:

^(?:Mrs?|Ms|[DE]r)\.

Regex demo

If there has to be a char A-Za-z following, you could also match optional whitespace chars preceding the character class

^(?:Mrs?|Ms|[DE]r)\.\s*[A-Za-z]

Regex demo

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