Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zkmark/a7ccca0761a6180e87fa99f2fbe9e1f4 to your computer and use it in GitHub Desktop.
Save zkmark/a7ccca0761a6180e87fa99f2fbe9e1f4 to your computer and use it in GitHub Desktop.
Obtener texto entre 2 caracteres y remplazar valor
let text = 'hello :name; ok :name2; ok2'
let the_value_to_search = ':'
let the_value_to_search2 = ';'
let the_new_value_to_replace = '+'
let regex_between = new RegExp(`${the_value_to_search}(.*?)${the_value_to_search2}`, 'gi');
const matches = text.matchAll(regex_between);
let the_text_end = Array.from(matches, x => x[1]).join(the_new_value_to_replace).toString();
console.log(the_text_end);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment