regular expression

1. Safari handles positive lookbehind assertions in regular expressions, denoted by (?<=…), abnormally

js
1
2
3
4
5
6
// The following code works fine in Chrome but throws an error in Safari.
"https://linlccc.com?theme=light".replace(/(?<=[?|&]theme=)\w+/, "dark");
// The solution is to use capturing groups and string replacement.
"https://linlccc.com?theme=light".replace(/([?|&]theme=)\w+/, "$1dark");

// Both of the execution results above are "https://linlccc.com?theme=dark"