简体   繁体   中英

how to use replace in javascript for special characters

I want to make this:

[:fr]french[:de]german[:en]english[:]

Look like this:

<!--:fr-->french<!--:de-->german<!--:en-->english<!--:-->

I have tried:

string.replace("[:", "<!--:");

and

string.replace("]", "-->");

but no luck,

Any help would be appreciated!

您可以:

str = str.replace(/\[(:[a-z]*)\]/g, "<!--$1-->");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM