需求如下:
比如有如下字符
String playCode;
String code;
String rid;
String message;
String body0code;
String body0needClothHat;
需要替換爲
String playCode = vars.get("playCode");
String code = vars.get("code");
String rid = vars.get("rid");
String message = vars.get("message");
String body0code = vars.get("body0code");
String body0needClothHat = vars.get("body0needClothHat");
可以使用notepad++ 正則表達式替換,效率可以提高很多。
規則解析
[A-Za-z0-9] : 匹配大小寫字母、0-9數字
(): 影響表達式匹配的順序(類似C++的小括號會影響表達式運算順序),並且用作表達式的分組標記(標記從1開始)如:([a-z]bc)smn\1匹配“tbcsmntbc”;
+:其左邊的字符被匹配至少一次(1次或多次)。如:be+匹配“be”或“bee”,但不匹配“b”
\1 : ([A-Za-z0-9]+)是該表達式的第一個分組,\1是匹配第一個分組匹配到的內容,也就是所謂的\1引用了第一個()匹配到的內容。