简体   繁体   English

正则表达式模式与提供的文件名不匹配

[英]Regex pattern isn't matching file name provided

I am new to regex patterns and I used regexr to make one, and it is not working the way I want it to.我是 regex 模式的新手,我使用 regexr 制作了一个,但它并没有按照我想要的方式工作。 On the site it does match the file name when I test it.在网站上,当我测试它时,它确实与文件名匹配。

But when I use it in my code to match all the files in subfolders with that name, it doesn't match any.但是当我在我的代码中使用它来匹配具有该名称的子文件夹中的所有文件时,它不匹配任何文件。

The pattern is模式是

/^_config\.[t]sx?$/g/

I am trying to match all the file names named _config.tsx in all subfolders using require context.我正在尝试使用 require 上下文匹配所有子文件夹中名为 _config.tsx 的所有文件名。

This is that code:这是那个代码:

const requireComponent = require.context(
    '../../main', // components folder
    true, // look subfolders
    /^_config\.[t]sx?$/ //regex for files
)

Thanks for reading.谢谢阅读。

Try without t in group chars ( [ and [ )尝试在组字符( [[ )中不使用t

/^_config\.tsx?$/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM