我需要創建laravel遷移,所以我已經使用Sublime Text中的正則表達式使用「替換文件」將我的SQL腳本轉換爲laravel遷移格式。嵌套正則表達式替換
我的問題是,我有由「表名」在約70桌以下字符串替換「@」字符:
Schema::table('tablename', function($table) {
$table->dropForeign('@_columnname_foreign');
});
其實我可以使用下面的表達式做到這一點:
(Schema::table\('([a-z]+)',[\s]*function\(\$table\)[\s]*{[\s]*\$table->dropForeign\(')@(_[a-z_]+'\);)
而在替代領域:
$1$2$3
,但我不知道該怎麼辦時,該表有一個以上的FK:
Schema::table('tablename1', function($table) {
$table->dropForeign('@_field1_foreign');
$table->dropForeign('@_field2_foreign');
$table->dropForeign('@_field3_foreign');
$table->dropForeign('@_field4_foreign');
$table->dropForeign('@_field5_foreign');
$table->dropForeign('@_field6_foreign');
});
我一直在使用這個網站來驗證我的正則表達式RegExr
@revo,我只是確保:SublimeTex2和SublimeText3正則表達式實現之間有區別。刪除我的評論。 –
這很奇怪。去除地雷。 @WiktorStribiżew – revo