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

102
Visualizações
Call Substring multiple times

I have a string and I want to remove this data like this \(f(x) = (a+b)\)
so i am thinking to get all subsstring and then make some operation on array. But it is giving me only one stripedHtml. So not able to get how to clean it. Just wants to remove this equations.

Result will be : Here’s the evidence

const filter_data = `<p>\(f(x) = (a+b)\)</p><p>\(f(x) = (a+db)\)</p><p>\(f(x) = (a+d+c+b)\)</p>
    <p>Here’s the evidence.</p>`
var strippedHtml = filter_data.substring(
  filter_data.lastIndexOf("\(") + 1,
  filter_data.lastIndexOf("\)")
);


console.log(strippedHtml)

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

0

You can use following regular expressions to obtain solution for only similar type of data you were provided

const filterData1 = `<p>\(f(x) = (a+b)\)</p><p>\(f(x) = (a+db)\)</p><p>\(f(x) = (a+d+c+b)\)</p><p>Here’s the evidence.</p>`
const filterData2 = `<p>\(f(x) = (a+b)\)</p><p>\(f(x) = (a+db)\)</p><p>\(f(x) = (a+d+c+b)\)</p><p>Here’s the evidence.</p><p>\(f(x) = (a+b)\)</p>`

const regEx1 = /<[^>]*>/g   //regular expression to remove all html tags
const regEx2 = /\([^\)]*\)/g  //regular expression to remove everything between \( and \)
const regEx3 = /[=)]/g  //regular expression to remove = and )

const result1 = filterData1.replace(regEx1,'').replace(regEx2,'').replace(regEx3,'').trim()
const result2 = filterData2.replace(regEx1,'').replace(regEx2,'').replace(regEx3,'').trim()

console.log("Result1 : ",result1);
console.log("Result2 : ",result2);

about 4 years ago · Juan Pablo Isaza Relatório

0

JS has a replace method for this that accepts RegExp:

const filter_data = `<p>\(f(x) = (a+b)\)</p><p>\(f(x) = (a+db)\)</p><p>\(f(x) = (a+d+c+b)\)</p>
    <p>Here’s the evidence.</p>`;
var strippedHtml = filter_data.replace(/\<.*?\(.*?>/g, "");

console.log(strippedHtml);

The RegExp searches for an < followed by a ( and then an > and replaces all appearances with an empty value.

In your string it will match two times and do a replace. Maybe you have to modify the RegExp to fit your real string as it would also match text nodes containing ( but that's what I would do at this point with the given data.

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