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

201
Views
replace words that starts with "(uuid: )"

I would like to replace text using javascript/regex

"TV "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched off."

with

TV 'my-samsung' is already switched off.

by removing text (UUID: ) and replace " with '

Looks like regex can be used

  \([\s\S]*?\) 

https://regex101.com/r/xXDncn/1

or have also tried using replace method in JS

   str = str.replace("(UUID", "");
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use

const str = '" "Tv "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched-off""';
console.log(
   str.replace(/\s*\(UUID:[^()]*\)/g, '').replace(/^[\s"]+|[\s"]+$/g, '').replaceAll('"', "'")
)

See the first regex demo. It matches

  • \s* - zero or more whitespaces
  • \(UUID: - (UUID: string
  • [^()]* - zero or more chars other than ( and )
  • \) - a ) char.

The g flag makes it replace all occurrences.

The second regex removes trailing and leading whitespace and double quotation marks:

  • ^[\s"]+ - one or more whitespaces and double quotes at the start of string
  • | - or
  • [\s"]+$ - one or more whitespaces and double quotes at the end of string.

The .replaceAll('"', "'") is necessary to replace all " with ' chars.

It is not a good idea to merge these two operations into one as the replacements are different. Here is how it could be done, just for learning purposes:

const str = '" "Tv "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched-off""';
console.log(
   str.replace(/^[\s"]+|[\s"]+$|\s*\(UUID:[^()]*\)|(")/g, (x,y) => y ? "'" : "")
)

That is, " is captured into Group 1, the replacement is now a callable, where x is the whole match and y is the Group 1 contents. If Group 1 matched, the replacement is ', else, the replacement is an empty string (to remove the match found).

about 4 years ago · Juan Pablo Isaza Report

0

you can try this

str.replace(/\(.*?\)/, "")
str.replace(/\(.*?\)/, "with")

--- update ---

const str = `"TV "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched off."`;
const a = str.replace(/"(.*?)\(.*\)(.*)"/, (a, b, c) => {
    return b.replace(/"/g, "'") + c
});
console.log(a); //TV 'my-samsung' is already switched off. 
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!