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

178
Views
Remove/ Replace span of Specific String from the sentence

I am trying to remove the span tag from string of sentence .Is it possible .?

My Input is as below :

divData = Welcome Hello <span> World </Span> ! Looking forward the great <span>things</span>.

Output I am looking for :

divData = Welcome Hello World ! Looking forward the great <span>things</span>.

what I have tried is :

  str = divData.replace(/<\/?span[^>]*>/g,"");

But above one is replacing all the span of all sentence.

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

0

Try this,

str = divData.replace(/<span[^>]*>/,"");
str = str.replace(/<\/?Span[^>]*>/,"");

(Removed 'g' flag) 'g' means global, it will replace everything in the string.

about 4 years ago · Juan Pablo Isaza Report

0

You may use replace here in non global mode, which will target the first span tag only:

divData = "Welcome Hello <span> World </span> ! Looking forward the great <span>things</span>.";
divData = divData.replace(/<span>\s*(.*?)\s*<\/span>/, "$1");
console.log(divData);

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!