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

135
Views
Remove unwanted matching text from string and get required value using js

I have string it contain unwanted html tags and text, so I want to remove unwanted matching text and get my required values:

Code:

var mystring = "<!-- html-text: 143 --> value 1  <!-- /html-text --><!-- html-text: 144 --> | <!-- /html-text --><!-- react-text: 145 --> value 3 <!-- /html-text --><!-- html-text: 146 -->, <!-- /html-text --><!-- html-text: 147 --> value 2 <!-- /html-text --><!-- html-text: 148 --> <!-- /html-text --><!-- html-text: 149 -->value 4 <!-- /html-text -->";
mystring = mystring.replace('<!-- html-text: 143 -->','');

console.log('str'+mystring);

Required output:

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

0

You can do this with regex:

var mystring = "<!-- html-text: 143 --> value 1  <!-- /html-text --><!-- html-text: 144 --> | <!-- /html-text --><!-- react-text: 145 --> value 3 <!-- /html-text --><!-- html-text: 146 -->, <!-- /html-text --><!-- html-text: 147 --> value 2 <!-- /html-text --><!-- html-text: 148 --> <!-- /html-text --><!-- html-text: 149 -->value 4 <!-- /html-text -->";
mystring = mystring.replace(/<!--.*?-->/g,'');

console.log(mystring);

Regex explanation:

  1. <!--...--> Marks the opening and ending of an HTML comment
  2. .* Matches any character zero or more times
  3. ? Remove "greedy matching" (match the least possible instead of most)
  4. g Global, meaning to replace all occurrences instead of just one
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!