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

154
Views
Regex para encontrar si la cadena multilínea no tiene etiquetas html o no

Necesito verificar si la cadena con varias líneas contiene etiquetas HTML (<>) o no.

 var regex= /^(?!.*<[^>]+>).*$/; console.log('istextWithoutHtml--', regex.test('Line1\nLine2'));\\ Expecting true, since it doesnt have html tags \\ Expecting false for these combinations, since it contains html tags in it \\ 'Line1<a>\nLine2' \\ 'Line1\nLine2<p>' \\ '<a></a>' \\ '<\img>' \\ '</a>\n</b>'

Prueba 1

 var regex1 = new RegExp(regex); console.log('istextWithoutHtml---', regex1.test('Line1\nLine2')); \\ false (I am expecting true here) console.log('istextWithoutHtml---', regex1.test('Line1<a>\nLine2')); \\ false

Prueba 2

 var regex2 = new RegExp(regex, 's'); console.log('istextWithoutHtml---', regex2.test('Line1\nLine2')); \\ true console.log('istextWithoutHtml---', regex2.test('Line1<a>\nLine2')); \\ true (I am expecting false here)

Prueba 3

 var regex3 = new RegExp(regex, 'm'); console.log('istextWithoutHtml---', regex3.test('Line1\nLine2')); \\ true console.log('istextWithoutHtml---', regex3.test('Line1<a>\nLine2')); \\ true (I am expecting false here)

¿Hay alguna forma de lograr la verificación de etiquetas HTML en la cadena de varias líneas?

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

0

Puedes usar

 /^(?![^]*<[^>]+>)[^]*/.test(text)

Detalles :

  • ^ - comienzo de la cadena
  • (?![^]*<[^>]+>) - inmediatamente a la derecha, no debe haber cero o más caracteres seguidos de < , uno o más caracteres que no sean > y luego un > carácter.
  • [^]* - cualquier cero o más caracteres tantos como sea posible
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!