我需要处理名称中包含某些关键字(例如“BOOK”)的文件。文件命名约定:
这个解决方案有效。但它区分大小写。但我如何使其不区分大小写
.*?-BOOK-.*?\.csv
当我有像“sometext-BOOK-sometext.csv”这样的文件时,它可以工作 但是,当我的文件全部为小写“sometext-book-sometext.csv”时,它不会捕获此文件。
这就是解决方案
(?i).*?-BOOK-.*?.csv
`(?i)`: This is a flag placed at the beginning of the regex to enable case-insensitive matching throughout the entire pattern.
`.*?`: Matches any character (zero or more times, non-greedy) - This captures any text before "-ITEM-".
`-BOOK-`: Matches the literal string "-ITEM-".
`.*?`: Matches any character (zero or more times, non-greedy) - This captures any text after "-ITEM-".
`.csv`: Matches the literal string ".csv" to ensure it's a CSV file.