Anonymously Replace string with Regex

# sion (6 years ago)

Emmmmm, pretty sorry for misleading you…

Your solution will not work if I just provide you a regex without telling you detail information, all I want is replace first and second word matched by the regex, nothing more.

# Peter Jaszkowiak (6 years ago)

All you have to do is write the regex differently:

input.replace(
  /(your )(\w+)( from )(\w+)/,
  (w, a, b, c, d) => `${a}${b.toUpperCase()}${c}${d.toLowerCase()}`
);