關(guān)于minecraft地圖扁平化轉(zhuǎn)檔(1.12.2>1.15.2)函數(shù)修改的記錄(番外篇-正則)
今天花了20分鐘時間稍微了解了一下n++的正則
https://www.cnblogs.com/kekec/p/5255475.html
這個網(wǎng)頁的介紹很好
然后我舉一個比較典型的例子
請先閱讀上述網(wǎng)頁中的教程然后再繼續(xù)往下看

替換前
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

注意此處執(zhí)行say 1的execute不被替換
那么該如何使用正則呢?
建議自己思考過后再往下看

我所用的方法:
查找:execute?(@a\[tag=a.*),limit=1(\])?~ ~ ~ tellraw
替換為:execute if entity \1\2 run tellraw
我將介紹里面每一個和正則有關(guān)的部分所起到的作用:
execute?(@a\[tag=a.*),limit=1(\])?~ ~ ~ tellraw
標(biāo)紅的這一對括號表示其中內(nèi)容被保存下來
在execute if entity \1\2 run tellraw中使用\1被調(diào)用
\+一個數(shù)字n相當(dāng)于將查找文本中的第n對括號中的內(nèi)容置于此位置
execute?(@a\[tag=a.*),limit=1(\])?~ ~ ~ tellraw
標(biāo)紅的這一對括號和execute if entity?\1\2run tellraw中標(biāo)紅的\2也同理
execute?(@a\[tag=a.*),limit=1(\])?~ ~ ~ tellraw
標(biāo)紅的這些\為轉(zhuǎn)義,想必使用過JSON文本的mc玩家都很熟悉了
execute?(@a\[tag=a.*),limit=1(\])?~ ~ ~ tellraw
標(biāo)紅的.表示此處可以為任意一個字符
execute?(@a\[tag=a.*),limit=1(\])?~ ~ ~ tellraw
標(biāo)紅的*表示此符號前的.的效果可以執(zhí)行無限次,相當(dāng)于a后面,之前加任何的字符都是符合條件的,以此才能在替換時包括a后所跟數(shù)字為一位數(shù)與兩位數(shù)的情況
execute?(@a\[tag=a.*),limit=1(\])?~ ~ ~ tellraw
標(biāo)藍(lán)的為文本(包括空格),其中tellraw是為了排除后面跟著say的情況,execute也是為了縮小范圍(但是例題里中不必要使用execute 使用盡量多的條件可以避免在眾多函數(shù)的文件中盡量少地誤傷其他指令),于是括號外的部分就被替換為execute if entity \1\2 run tellraw中標(biāo)藍(lán)的文本(包括空格),而\1\2之間的,limit=1就被刪除了

這個例子包含了添加、刪除、排除、轉(zhuǎn)義、保留、部分為任意文本等情況,個人認(rèn)為足以適用大部分函數(shù)文件的修改了,本系列正篇請看本人的個人空間