Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
Regex to find whether the multiline String is without html tags or not

I need to check whether the string with multiple lines contains any HTML tags(<>) in it or not.

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>'

Trial 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

Trial 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)

Trial 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)

Is there any way to achieve both HTML tag check in the multiple line string.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use

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

Details:

  • ^ - start of string
  • (?![^]*<[^>]+>) - immediately to the right, there should be no zero or more chars followed with <, one or more chars other than > and then a > char.
  • [^]* - any zero or more chars as many as possible
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda