我正在从 html 迁移到 Drupal。使用迁移模块。
在我们的自定义迁移脚本中,我需要匹配除图像文件夹之外的所有文件夹中的所有 .html 文件。
将此正则表达式传递给 $list_files = new MigrateListFiles([],[],$regex)
下面是html文件的格式
/magazines/sample.html
/test/index.html
/test/format_ss1.html
/test/folder/newstyle_1.html
/images/two.html
我只需要获取前 2 个 html 文件,即我们排除以“_[0-9]”和“_ss[0-9]”结尾的文件以及图像文件夹中的 .hmtl 文件。
我已经成功排除了 3 和 4,但我无法排除图像文件夹中的 .html 文件。
$regex = '/[a-zA-Z0-9\-][^_ss\d][^_\d]+\.html/'; //this will do for 3 and 4 files
但我需要排除图像文件夹..
我试过
$regex = '/[^images\/][a-zA-Z0-9\-][^_ss\d][^_\d]+\.html/'; // not working
在 PHP 脚本中它将起作用
$regex = '~^(?!/images/)[a-zA-Z0-9/-]+(?!_ss\d|\d)\.html$~' //works in php script
谁能帮我解决这个问题..
最佳答案
尝试
/((?!images)[0-9a-zA-Z])+/[^_]*[^\d]+\.html
匹配:
/magazines/sample.html
/test/index.html
/test/folder/newstyle.html
/test/format_ss.html
不匹配:
/test/format_ss1.html
/test/folder/newstyle_1.html
/images/two.html
/images/1.html
/test/folder/newstyle1.html
/test/folder/newstyle_12.html
这可以接受吗?
关于regex - 使用正则表达式排除文件夹并匹配根文件夹中的所有 .html 模式文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20214115/