关于minecraft地图扁平化转档(1.12.2>1.15.2)函数修改的记录(番外篇-正则)
今天花了20分钟时间稍微了解了一下n++的正则
https://www.cnblogs.com/kekec/p/5255475.html
这个网页的介绍很好
然后我举一个比较典型的例子
请先阅读上述网页中的教程然后再继续往下看

替换前
execute @a[tag=a1,limit=1] ~ ~ ~ tellraw @a 1
execute @a[tag=a10,limit=1] ~ ~ ~ tellraw @a 1
execute @a[tag=a10,limit=1] ~ ~ ~ say 1

替换后
execute if entity @a[tag=a1] run tellraw @a 1
execute if entity @a[tag=a10] run tellraw @a 1
execute @a[tag=a10,limit=1] ~ ~ ~ say 1

注意此处执行say 1的execute不被替换
那么该如何使用正则呢?
建议自己思考过后再往下看

我所用的方法:
查找:execute (@a\[tag=a.*),limit=1(\]) ~ ~ ~ tellraw
替换为:execute if entity \1\2 run tellraw
我将介绍里面每一个和正则有关的部分所起到的作用:
execute (@a\[tag=a.*),limit=1(\]) ~ ~ ~ tellraw
标红的这一对括号表示其中内容被保存下来
在execute if entity \1\2 run tellraw中使用\1被调用
\+一个数字n相当于将查找文本中的第n对括号中的内容置于此位置
execute (@a\[tag=a.*),limit=1(\]) ~ ~ ~ tellraw
标红的这一对括号和execute if entity \1\2run tellraw中标红的\2也同理
execute (@a\[tag=a.*),limit=1(\]) ~ ~ ~ tellraw
标红的这些\为转义,想必使用过JSON文本的mc玩家都很熟悉了
execute (@a\[tag=a.*),limit=1(\]) ~ ~ ~ tellraw
标红的.表示此处可以为任意一个字符
execute (@a\[tag=a.*),limit=1(\]) ~ ~ ~ tellraw
标红的*表示此符号前的.的效果可以执行无限次,相当于a后面,之前加任何的字符都是符合条件的,以此才能在替换时包括a后所跟数字为一位数与两位数的情况
execute (@a\[tag=a.*),limit=1(\]) ~ ~ ~ tellraw
标蓝的为文本(包括空格),其中tellraw是为了排除后面跟着say的情况,execute也是为了缩小范围(但是例题里中不必要使用execute 使用尽量多的条件可以避免在众多函数的文件中尽量少地误伤其他指令),于是括号外的部分就被替换为execute if entity \1\2 run tellraw中标蓝的文本(包括空格),而\1\2之间的,limit=1就被删除了

这个例子包含了添加、删除、排除、转义、保留、部分为任意文本等情况,个人认为足以适用大部分函数文件的修改了,本系列正篇请看本人的个人空间