Created
December 2, 2022 21:08
-
-
Save zkmark/a7ccca0761a6180e87fa99f2fbe9e1f4 to your computer and use it in GitHub Desktop.
Obtener texto entre 2 caracteres y remplazar valor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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