我正在尝试用模板替换文件的某个部分,当我将所有模板粘贴到替换字段并单击替换时,该模板会被切断。
我的搜索是:
\t// MODDED STUFF HERE.*// END MODDED STUFF
我试图用以下内容替换它:
\t// MODDED STUFF HERE\r\n\t\r\n\trmCreateTrigger\("MyTrigger"\+1\);\r\n\r\n\trmSwitchToTrigger\(rmTriggerID\("MyTrigger1"\)\);\r\n\tfor\(i=1; <rmGetNumberPlayersOnTeam\(0\)\+1\)\{\r\n\t\tfor\(j=0; <10\)\{\r\n\t\t\t// Titan Shield\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",452\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\t\r\n\t\t\t// Relic Eye of Horus\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",194\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\}\r\n\t\t\r\n\t\tfor\(j=0; <4\)\{\r\n\t\t\t// Acupuncture\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",562\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t\t// Temple of Healing\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",341\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\}\r\n\t\t\r\n\t\tfor\(j=0; <2\)\{\r\n\t\t\t// Thurisaz Rune\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",328\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t\t// Jade Rabbit\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",566\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t\t// Relic Head of Orpheus\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",196\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t\t// Relic Kithara of Apollo\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",201\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\t\r\n\t\t\t// Relic Pelt of Argus\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",369\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t\t// Relic Oseberg Wagon\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",370\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\}\r\n\t\t\r\n\t\t// Mythic Rejuvenation\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",432\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Heroic Renewal\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",433\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Hammer of the Gods\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",289\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Meteoric Iron Mail\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",290\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Dragonscale Shields\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",291\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Dwarven Mail\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",153\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Dwarven Weapons\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",155\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Relic Fetters of Fenrir\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",199\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\}\r\n\r\n\trmSetTriggerPriority\(3\);\r\n\trmSetTriggerActive\(true\);\r\n\trmSetTriggerRunImmediately\(true\);\r\n\trmSetTriggerLoop\(false\);\r\n\t\r\n\trmCreateTrigger\("MyTrigger"\+2\);\r\n\r\n\trmSwitchToTrigger\(rmTriggerID\("MyTrigger2"\)\);\r\n\t\r\n\trmAddTriggerCondition\("Timer"\);\r\n\trmSetTriggerConditionParamInt\("Param1",1\);\r\n\t\r\n\tfor\(i=1; <rmGetNumberPlayersOnTeam\(0\)\+1\)\{\r\n\t\trmAddTriggerEffect\("Grant Resources"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParam\("ResName","Food"\);\r\n\t\trmSetTriggerEffectParamInt\("Amount",2\);\r\n\t\t\r\n\t\trmAddTriggerEffect\("Grant Resources"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParam\("ResName","Wood"\);\r\n\t\trmSetTriggerEffectParamInt\("Amount",2\);\r\n\t\t\r\n\t\trmAddTriggerEffect\("Grant Resources"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParam\("ResName","Gold"\);\r\n\t\trmSetTriggerEffectParamInt\("Amount",2\);\r\n\t\}\r\n\t\r\n\trmSetTriggerPriority\(3\);\r\n\trmSetTriggerActive\(true\);\r\n\trmSetTriggerRunImmediately\(false\);\r\n\trmSetTriggerLoop\(true\);\r\n\t\r\n\t// END MODDED STUFF
但其中一部分被切断了。我希望能够使用替换功能替换它而不是直接复制和粘贴它是因为我需要对多个文件(超过30个)进行完全相同的替换,因此使用它来实现它会更有效率查找和替换功能,而不是每次复制和粘贴。
有没有办法做到这一点,没有替换文本的一部分被我假设的字符限制切断?或者,如果有另一种方法可以做我需要的并不是非常复杂的话,我可以接受建议。
答案 0 :(得分:0)
使用Notepad ++和TextWrangler等软件 - 正如您所指出的那样 - 在您可以在替换字段中粘贴的字符数量方面受到限制。
如果你想做这种替换,你将不得不使用Python,PHP等编程语言。
例如,您可以使用以下代码在PHP中执行此操作:
<?php
$replace_text = $_POST['replace'];
$target_text = ' \r\n\t\r\n\trmCreateTrigger\("MyTrigger"\+1\);\r\n\r\n\trmSwitchToTrigger\(rmTriggerID\("MyTrigger1"\)\);\r\n\tfor\(i=1; <rmGetNumberPlayersOnTeam\(0\)\+1\)\{\r\n\t\tfor\(j=0; <10\)\{\r\n\t\t\t// Titan Shield\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",452\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\t\r\n\t\t\t// Relic Eye of Horus\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",194\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\}\r\n\t\t\r\n\t\tfor\(j=0; <4\)\{\r\n\t\t\t// Acupuncture\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",562\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t\t// Temple of Healing\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",341\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\}\r\n\t\t\r\n\t\tfor\(j=0; <2\)\{\r\n\t\t\t// Thurisaz Rune\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",328\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t\t// Jade Rabbit\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",566\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t\t// Relic Head of Orpheus\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",196\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t\t// Relic Kithara of Apollo\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",201\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\t\r\n\t\t\t// Relic Pelt of Argus\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",369\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t\t// Relic Oseberg Wagon\r\n\t\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\t\trmSetTriggerEffectParamInt\("TechID",370\);\r\n\t\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\}\r\n\t\t\r\n\t\t// Mythic Rejuvenation\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",432\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Heroic Renewal\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",433\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Hammer of the Gods\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",289\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Meteoric Iron Mail\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",290\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Dragonscale Shields\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",291\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Dwarven Mail\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",153\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Dwarven Weapons\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",155\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\t\r\n\t\t// Relic Fetters of Fenrir\r\n\t\trmAddTriggerEffect\("Set Tech Status"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParamInt\("TechID",199\);\r\n\t\trmSetTriggerEffectParamInt\("Status",4\);\r\n\t\}\r\n\r\n\trmSetTriggerPriority\(3\);\r\n\trmSetTriggerActive\(true\);\r\n\trmSetTriggerRunImmediately\(true\);\r\n\trmSetTriggerLoop\(false\);\r\n\t\r\n\trmCreateTrigger\("MyTrigger"\+2\);\r\n\r\n\trmSwitchToTrigger\(rmTriggerID\("MyTrigger2"\)\);\r\n\t\r\n\trmAddTriggerCondition\("Timer"\);\r\n\trmSetTriggerConditionParamInt\("Param1",1\);\r\n\t\r\n\tfor\(i=1; <rmGetNumberPlayersOnTeam\(0\)\+1\)\{\r\n\t\trmAddTriggerEffect\("Grant Resources"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParam\("ResName","Food"\);\r\n\t\trmSetTriggerEffectParamInt\("Amount",2\);\r\n\t\t\r\n\t\trmAddTriggerEffect\("Grant Resources"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParam\("ResName","Wood"\);\r\n\t\trmSetTriggerEffectParamInt\("Amount",2\);\r\n\t\t\r\n\t\trmAddTriggerEffect\("Grant Resources"\);\r\n\t\trmSetTriggerEffectParamInt\("PlayerID",i\);\r\n\t\trmSetTriggerEffectParam\("ResName","Gold"\);\r\n\t\trmSetTriggerEffectParamInt\("Amount",2\);\r\n\t\}\r\n\t\r\n\trmSetTriggerPriority\(3\);\r\n\trmSetTriggerActive\(true\);\r\n\trmSetTriggerRunImmediately\(false\);\r\n\trmSetTriggerLoop\(true\);\r\n\t\r\n\t ';
$replace_text = preg_replace("/(?<=HERE)(\.\*)/", $target_text , $replace_text);
echo $replace_text;
?>
保存上面的PHP代码,并将其命名为a.php
。
添加另一个文件以使PHP工作,此文件将为HTML
并在其中复制以下代码,并将其另存为a.html
<form action="b.php" method="POST">
Text: <input style="width: 500px; height: 80px; margin:5px; padding: 5px;" type="text" name="replace">
<br /><br />
<input value="replace" style="margin:5px; width: 100px; height: 40px;" type="submit">
</form>
现在,在任何localhost中运行a.html文件,它应该可以工作!
这是我使用的正则表达式,你可以改变它 - 如果你愿意 - 从PHP文件'a.php'来满足你的需要。
(?<=HERE)(\.\*)