我看过this示例并尝试使用 this website ,但我仍然卡住了。
我需要匹配 node_modules
文件夹中的所有内容,react-native-calendars
及其子目录/子目录除外。
我想我需要使用 Negative Lookahead,这是我现在的位置:
new RegExp (/node_modules\/(?!.*(react-native-calendars))/)
任何帮助将不胜感激!谢谢。
最佳答案
这行得通。
原始 ^.*?/node_modules(?:/(?!react-native-calendars(?=/|$))[^/\r\n]*)*$
< br/>
正则表达式文字 /^.*?\/node_modules(?:\/(?!react-native-calendars(?=\/|$))[^\/\r\n]*)*$/
它匹配所有项目与/node_modules
文件夹和
在每个 /
设置一个验证点来检查坏文件夹。
如果您使用的是单项字符串,则可以删除 (?m)
。
如果您希望它不区分大小写,您可以根据需要添加 (?i)
。
在 JS 中,您将它们添加到文字语法 /regex/mi
我已经检查过了,但是如果你有一些示例输入我可以链接
给在线测试人员 (regex101.com)。
展开
^ # BOL
.*? # Up until
/node_modules # Required 'node_modules'
(?: # Cluster
/ # / folder start
(?! # Assert cannot be the bad folder
react-native-calendars
(?= / | $ ) # Bad folder end
)
[^/\r\n]* # Ok, get up until start of next folder
)* # Cluster end, do 0 to many times
$ # EOL
关于javascript - 正则表达式匹配 "everything but"与 webpack 的 kebab-case,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45196653/