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

205
Views
Remove a sub-string in a string to rewrite a robust xpath

I need to remove the value attribute from this xpath. (In this example there are two value attributes).

I create the xpath in a string:

"xpath": "//iframe[@title=\"s='replaceable-modal-title'>Compléter mes entretiens</span><input type='hidden' id='assessDurationIdverif' value='2091' /><input type='hidden' id='employeeIdverif' value='1368' />\"]/html/body/div[2]/section/div/div[4]/div/form/div[2]/div/div[2]/div/div/textarea"

My first idea was to use the String#replace method to replace attribute's value with an empty string:

string.replace(/value=(2091)/g,'test') 

My problem is that the value attribute does not have the same value when I refresh the page.

I just want to know how to generically replace the number by undefined character.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You're on the right track with String#replace and a regular expression.

To handle the value attribute changing when the page reloads, use the \d digit character class which represents any character in 0-9. Using \d* matches zero or more digits and \d+ matches one or more digits.

Here's an example that matches all value attributes with digits in their values and replaces the whole attribute with an empty string:

const foo = "//iframe[@title=\"s='replaceable-modal-title'>Compléter mes entretiens</span><input type='hidden' id='assessDurationIdverif' value='2091' /><input type='hidden' id='employeeIdverif' value='1368' />\"]/html/body/div[2]/section/div/div[4]/div/form/div[2]/div/div[2]/div/div/textarea";

const bar = foo.replace(/value='\d+'/g, '');

console.log(foo);
console.log(bar);

about 4 years ago · Santiago Gelvez 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!