I'm trying to use Regex in javascript. Lets take this scenario,
str = "This; is; John; & Jane;"
The result I need,
str= "This* is* John* & Jane*"
This is what I have tried,
str.replace(/\^(?!&)\w+;\s/g, "*");
Please help. Thank you.
Try
str.replace(/(^|\s)([^&]\S+?);(?=$|\s)/g, "$1$2*")
You cannot do that without capturing groups because that would require a lookbehind assertion, which Javascript doesn't support.
试试这个:
str.replace(/((^| )[^&]\w+?);/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.