Question

I'm still very new to regex, so I think I can determine whether a string ends with a case-insensitive .csv:

(\\.(?i)(csv))

However, I do not know how to check that everything before that is at least one valid Windows filename character except an underscore, one underscore, and at least one valid Windows filename character except an underscore.

How can this be done?

Was it helpful?

Solution

Try using this regex for starters: [\\dA-Za-z]+_[\\dA-Za-z]+(\\.(?i)(csv)).

It takes the part you had checking for the .csv and adds a little more in front of it. It can be broken down into smaller parts:

  1. [\\dA-Za-z]+: any digit (\d), a-z case insensitive. At least one (+), could be more.
  2. _: exactly one underscore
  3. [\\dA-Za-z]+: any digit, a-z case insensitive. At least one (+), could be more.
  4. (\\.(?i)(csv)): your already existing .csv check.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top