Find key words on File name using regex

33 Views Asked by At

I need to process files that have some key word (eg. "BOOK") in their names. The files naming conventions:

This solution works. But it's case sensitive. But how do I make it case insensetive

.*?-BOOK-.*?\.csv 

When i have my file like "sometext-BOOK-sometext.csv" it works But when my file is all lower case "sometext-book-sometext.csv" it does not catch this file.

1

There are 1 best solutions below

0
Data Engineer On

This is the solution

(?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 "-BOOK-".

-BOOK-: Matches the literal string "-BOOK-".

.*?: Matches any character (zero or more times, non-greedy) - This captures any text after "-BOOK-".

.csv: Matches the literal string ".csv" to ensure it's a CSV file.