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?

有帮助吗?

解决方案

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.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top