javascript - Regex escape all matches for <!here|@here> with @here or blank -


i have string, such this:

var mystring = 'hi, <!here|@here>'; 

i'm trying escape might misunderstood html api, thought regex perfect, can't figure out.

ideal output after running on above string:

hi, @here

this i've tried far:

var result = mystring.replace(/(<!.*\|.*)@.*(>)/gm,' ');  console.log(string,result); 

i'm getting blank response here. testing regex101 in meantime.

presence of dot-star .* - as being greedy - make problems in regular expression. don't need trailing , leading dot-stars @ otherwise consume in input string.

also remember not use dot-star when want stop @ specific point may not stop @ right place.

var mystring = 'hi, <!here|@here>';  var result = mystring.replace(/<!(.*?)\|@\1>/g, '@$1');  console.log(result);


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -