Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
Javascript RegExp verifica que la cadena termina con la etiqueta abierta html + cualquier cosa menos una etiqueta

Me gustaría verificar que una cadena termina con cualquier Etiqueta abierta seguida o no por un texto

por ejemplo:

 <div>some text here

o

 <span>some text here

debe coincidir

pero

 <div>some text here</div>

o

 <h1>some text here</h1>

no debe

Traté de encontrar una solución (lo siento, no soy un profesional de expresiones regulares)

 let anyOpenTag = '<([^/>][^>])*>'; let anyCloseTag = '</[^/>][^>]*>'; let neitherOpenNorCloseTag = `[^(${anyOpenTag}|${anyCloseTag})]`; let regex = new RegExp( escapeRegExp(`${anyOpenTag}${neitherOpenNorCloseTag}*$`), 'gi');
  1. Establecí una variable "anyOpenTag" en una expresión regular que verifica si es una etiqueta abierta como ( <p> , <div> , <span> etc...

  2. Establecí una variable "anyCloseTag" en una expresión regular que verifica si es una etiqueta de cierre como ( </p> , </div> , etc...)

  3. Establecí una variable "niOpenNorCloseTag" que intenta combinar los dos y compruebo si no es uno de ellos usando [^....]

finalmente verifico si la expresión regular coincide con anyOpenTag + niOpenNorCloseTag

lamentablemente no me funciona, precisamente la parte que verifica "niAbrirNiCerrarEtiqueta"

Se agradece su ayuda, incluso si tiene una expresión regular mejor, se lo agradecería.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Basado en sus ejemplos, este fragmento funciona:

 const regex = /<.*>.*<\/.*>/g const regexString = (regex) => { return (s) => { return !s.match(regex) } } const validateString = regexString(regex) const strings = [ '<div>some text here', '<span>some text here', '<div>some text here</div>', '<h1>some text here</h1>', ] const validated = strings.map(validateString) console.log('Result:', validated)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!