*To get the match for id:*

*string idPattern = @"_[1-9]{1,4}\.sql";*

if match, then use *idSubpattern *to get exact version number from value of
the above match

*string idSubPattern = @"[1-9]{1,4}";*

*Pattern to get project name*

*string procnamePattern = @"_.*_";*

remove the first and the last underscore from the received value of the
match to get projname

*Pattern to get Proc name*

*string projnamePattern = "[^_]*_";*

remove the first and the last underscore from the received value of the
match to get procname


On Mon, Nov 8, 2010 at 9:46 PM, rbr <[email protected]> wrote:

> I was hoping someone with far more experience with regular
> expressions, particularly in .NET, could help me come up with a
> pattern. I have a program that will be reading in sql files and
> creating a deployment manifest based on the files. I need to match the
> file names to first, validate that they match a predetermined pattern.
> Then, extract certain parts of the file name for metadata in the
> manifest. The file nameing pattern is like the following:
>
> <Project>_<ProcName>_<Version>.sql
>
> So, for example, I may have a file named
> MyProj_sp_GetCustomers_By_ID_2.sql. I need to first do a match on the
> name to verify that it ends in a number between 1 and 9999. I will
> then have to assume that the file was named properly (this is a new
> naming sceme and numbers were not allowed in the proc names
> previously). the next step will be to extract the Project, ProcName,
> and Version to properties.
>
> All-in-all this seems relatively simple. However, my sticking point is
> the proc name. It can be any length and contain 0 or any number of
> underscores. How do I create a regex that essentially "says" the
> following:
>
>  - Project name is everything up to the firt underscore.
>  - Version is a numeric value between 1 - 9999 that comes after the
> last underscore and before the file extension.
>  - The procedure is everything in-between.
>
> It seem like this should not be so difficult but, for some reason I am
> failing in coming-up with it.
>
> Any help is greatly appreciated.
>
> TIA!
>
> rbr

Reply via email to