Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

78
Vistas
REGEX-JAVASCRIPT Unable to find pattern

I am trying to figure how I can search for a pattern that gives me only digits or digits followed by only one letter. I know I can use /\D\g to find only digits but I dont know how to find digits with only one letter after it. The letters can only be the following:['a','A','b','B','c','C','d','D','n','N','e','E','s','S','w','W']

  const testPattern = /[A-Za-z][0-9]/
  console.log('item_10a_object10a'.pattern(testPattern))
7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First, you need to group the whole thing with (), and end with /g so it matches multiple groups.

If you want digits first then a number, you need to put the letter block after the numbers: ([0-9][A-Za-z])

If you want multiple digits to match, you need a + after the numbers block: [0-9]+

All together: /([0-9]+[A-Za-z])/g

For reference, \d does the same thing as [0-9], so you could do /(\d+[A-Za-z])/g instead

LPT: use regex101 to build and test regex queries

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos