156 "CAT:错误使用标题替换模板的页面",
157 /{{\s*:?\s*(?:Template\s*:|[模样樣]板\s*:|T\s*:)?\s*(?:[标標][题題]替[换換]|替[换換][标標][题題]).*}}\n?/gis,
158 "",
159 /^Category:需要更换为(?:标题格式化|小写标题)的页面$/160 );
161 // await cleaner(
162 // "CAT:错误使用NoSubpage的页面",
154 );
155 await cleaner(
156 "CAT:错误使用标题替换模板的页面",
157 /{{\s*:?\s*(?:Template\s*:|[模样樣]板\s*:|T\s*:)?\s*(?:[标標][题題]替[换換]|替[换換][标標][题題]).*}}\n?/gis,158 "",
159 /^Category:需要更换为(?:标题格式化|小写标题)的页面$/
160 );
145 );
146 await cleaner(
147 "CAT:需要更换为小写标题的页面",
148 /{{\s*:?\s*(?:Template\s*:|[模样樣]板\s*:|T\s*:)?\s*(?:[标標][题題]替[换換]|替[换換][标標][题題]).*}}\n?/gis,149 "{{小写标题}}"
150 );
151 await cleaner(
140 );
141 await cleaner(
142 "CAT:需要更换为标题格式化的页面",
143 /{{\s*:?\s*(?:Template\s*:|[模样樣]板\s*:|T\s*:)?\s*(?:[标標][题題]替[换換]|替[换換][标標][题題]).*}}\n?/gis,144 "{{标题格式化}}"
145 );
146 await cleaner(
136 await bot.login().then(async () => {
137 await cleaner(
138 "CAT:错误使用标题格式化的页面",
139 /{{\s*:?\s*(?:Template\s*:|[模样樣]板\s*:|T\s*:)?\s*[标標][题題]格式化.*}}\n?/gi140 );
141 await cleaner(
142 "CAT:需要更换为标题格式化的页面",
33 console.log("跳过页面");
34 } else if (
35 result1.query.pages[i].revisions[0].content.match(
36 /{{:?(?:Template:|[模样樣]板:|T:)?(?:施工中|[编編][辑輯]中|inuse)/gi 37 ) !== null
38 ) {
39 console.log("施工中");
26 );
27 if (
28 new RegExp(
29 /^(?:Template:Sandbox|Template:沙盒|模块:Sandbox)\// 30 ).test(result1.query.pages[i].title) ||
31 new RegExp(skipTitle).test(result1.query.pages[i].title)
32 ) {
24 const result1 = await bot.doEdit({
25 title: result0.query.pages[i].title,
26 text: result0.query.pages[i].revisions[0].content.replace(
27 /fallback *?= *?约?(\d{0,3})[,,]?\s?(\d{0,3})[,,]?\s?(\d{0,3})[,,]?\s?(\d{0,3})\s?[\+\-+]?/g,28 "fallback=$1$2$3$4"
29 ),
30 summary: "fallback参数更新",
It is recommended to use the u
flag with regular expressions.
The u
flag has two effects:
- It enables correct handling of UTF-16 surrogate pairs.
- It ensures the correct behavior of regex character ranges.
/^[👍]$/.test("👍") //→ false
/^[👍]$/u.test("👍") //→ true
For historical reasons, JavaScript regular expressions tolerate syntax errors.
For example, /\w{1, 2/
is a regex that would throw a syntax error, but JavaScript chooses not to.
It matches strings such as "a{1, 2"
instead.
This behaviour is defined in Annex B of the Javascript specification.
The u
flag disables the recovering logic Annex B
of the Javascript specification.
This way, you can find errors early.
It can therefore be thought of as a "strict mode" for RegEx literals.
This issue is raised when:
- A regular expression contains unicode property escapes i.e \p{<property-name>}
- A regular expression contains 4 bytes characters like emojis or some special characters
Bad Practice
const a = /aaa/
const b = /bbb/gi
const c = new RegExp("ccc")
const d = new RegExp("ddd", "gi")
Recommended
const a = /aaa/u
const b = /bbb/giu
const c = new RegExp("ccc", "u")
const d = new RegExp("ddd", "giu")
// This rule ignores RegExp calls if the flags are not a compile time constant.
function f(flags) {
return new RegExp("eee", flags)
}