更新时间:2023-02-23 14:40:34
我今天早些时候使用正则表达式做了类似的事情: / p>
I did something similar in a question earlier today using regexes:
str = str.replace(/<title>[\s\S]*?<\/title>/, '<title>' + newTitle + '<\/title>');
应该找到并替换它。 [\s\S] *?
意味着[包括空格和换行符的任何字符]任意次数,使星号不贪心,因此它会在找到< / title>
时停止(更快)。
That should find and replace it. [\s\S]*?
means [any character including space and line breaks]any number of times, and the ? makes the asterisk "not greedy," so it will stop (more quickly) when it finds </title>
.