What should be the regular expression for
<something>_<something else>.xml
I am trying below but It doesn't return any matched for valid pattern.
Regex.Matches(file.Name, @"^.[a-z0-9][_][a-z0-9].[Xx][Mm][Ll]$")
What should be the regular expression for
<something>_<something else>.xml
I am trying below but It doesn't return any matched for valid pattern.
Regex.Matches(file.Name, @"^.[a-z0-9][_][a-z0-9].[Xx][Mm][Ll]$")
It is not clear what you are trying to achieve.
Are you tryng to get a particular part of the file name?
Please edit your original question, and add what your final goal is.
This way should work too:
Regex.Matches(file.Name, "[a-z0-9]+_([a-z0-9]+[_-])*[a-z0-9]+[.]xml$", RegexOptions.IgnoreCase);
Since the suffix may be uppercase or lowercase, you need to use the Regex.Matches overload with RegexOptions as a parameter.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Theoretically, “something” can be expressed with “.+”, but it seems that you only accept letters and digits, therefore try this expression:
(?i)^[a-z0-9]+_[a-z0-9]+[.]xml$
If you need something special, then explain the rules and show examples.
(To insert the code try using the "101" button, because your expression is probably distorted).
Hello,
Your expression is not working.
My input can be
Definition_53d60b07-4d5b-bc8f-e1f8-fe261f58caae.xml
Definition_53d60b07-4d5b-bc8f-e1f8-fe261f58caae.XML
File_Name_53d60b07-4d5b-bc8f-e1f8-fe261f58caae.xml
File123_53d60b07-4d5b-bc8f-e1f8-fe261f58caae.xml
File_123_53d60b07-4d5b-bc8f-e1f8-fe261f58caae.XML
In above case file extension can be in both lower case and upper case.
Before extension It will always have '_<Alpha numeric string having only '-' as special character in it>
Whereas It will always start with any string or characters excepted by file name.
10 people are following this question.
Insert a node as child ,before or after a node in nested dynamic JSON Node using C#
Visual Studio 2019: Undefined behavior in a C++/CLI wrapper project.
Example for how to get Package Metadata from Azure DevOps Rest-Api Artifacts using c#
How to collapse individual nested grids/stackpanels inside a grid?