Check for underscore wrapped any valid Windows filename characters except underscore and csv extension

StackOverflow https://stackoverflow.com/questions/23227706

문제

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