我在PHP类方法中有一个关联数组,如下所示:
// ...
$filters = [
self::FILTER_CREATION_DATE => "Base/*/Creation/Date.php",
self::FILTER_CREATION_DATE_BETWEEN => "Base/*/Creation/Date.php",
self::FILTER_CREATION_DATE_GREATER => "Base/*/Creation/Date.php",
self::FILTER_CREATION_DATE_GREATER_OR_EQUAL => "Base/*/Creation/Date.php",
self::FILTER_CREATION_DATE_LESS => "Base/*/Creation/Date.php",
self::FILTER_CREATION_DATE_LESS_OR_EQUAL => "Base/*/Creation/Date.php",
];
// ...
我想做的是将此字符串转换为:
self::FILTER_CREATION_DATE_BETWEEN => "Base/*/Creation/Date.php",
对此:
self::FILTER_CREATION_DATE_BETWEEN => "Base/*/Creation/Date/Between.php",
我想使用RegEx扩展字符串,但其余部分保持不变。我需要这样做是因为定义了超过120个以*_BETWEEN
结尾的常量。
我该怎么做?
答案 0 :(得分:1)
在Intellij编辑器或免费的Notepad ++中,您可以找到并用正则表达式替换。 我确定其他IDE具有类似的功能
self::([_A-Z]+)_BETWEEN => "(.*)/Date.php"(,)*
self::$1_BETWEEN => "$2/Date/Between.php"$3
正则表达式通过将搜索的变量组成部分包装在()
在替换操作中,您可以按$1
,$2
等顺序引用它们。