• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

82
Vistas
Regex to match hashtag character with string format in javascript

I need a Regex to match a certain string format in javascript,

A hashtag symbol '#' has to be first and last character , There must be strings between these two characters,

If the string is more than one there must be two hashtag '##' symbol between each of them there is no limit to strings number.

Ex.

  1. #string1##string2##string3##...##string4#

  2. #string1#

  3. #string##string2#

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

0

You can check the below regex with this pattern

#[^\#]+#: All characters (except #) between ##

(#[^\#]+#)+: At least a string matched the pattern

^ and $: Start and end of regex

const checkRegex = (value) => {
  const regex = /^(#[^\#]+#)+$/
  return regex.test(value)
}

console.log(checkRegex("#test")) //false
console.log(checkRegex("#test#")) //true
console.log(checkRegex("#test##")) //false
console.log(checkRegex("#test##test#")) //true
console.log(checkRegex("#test##test##")) //false
.as-console-wrapper { max-height: 100% !important; top: 0; }

about 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda