regex - 使用正则表达式排除文件夹并匹配根文件夹中的所有 .html 模式文件

标签 regex drupal migration

我正在从 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/

相关文章:

mysql - 如何使用 MySQL 字符串函数在单词中插入空格?

javascript - JavaScript 的正则表达式符号有什么问题?

Drupal-Salesforce 与 NuSOAP

drupal - 从一个域重定向到另一个域但保留请求的页面

ios - 使用魔法记录的核心数据迁移

发现 C++ 正则表达式子字符串错误模式

Javascript:正则表达式字符串中的转义字符问题?

javascript - Flexslider 缩略图点击问题 - 中间问题

oracle - 在 grails 数据库迁移中使用 PL SQL

ruby-on-rails - 如何在不花很长时间的情况下更改大型 Postgres 表的默认值?