|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need some help finishing up my Regular Expression pattern
Greetings,
I am trying to parse/validate some user-input for an app I am writing that merges several files into our master database. The files are in the following storage format... {drive}\{Misc Folders}\Cust{Customer Number}\{Season}{Year}\{Misc CSV file/table names}.CSV For example... p:\folder1\folder2\might_have_this_folder_too\CUST100\F00\ORDERS.CSV I have the code to validate the drive (or \\server if used instead of drive letter or mapped drive), and the code for validating the customer folder on down through the path/tree, but I am having troubles accounting for the fact that this data might reside in any number of sub folders. So essentially, if the user input is as such... p:\CUST100\F00\ORDERS.CSV My code would work great so far. Here is an example of what I have so far... ^(?P<StorageResource>(?:[a-zA-Z]{1} |(?:\\{2}[a-zA-Z0-9-_ ]+))\\CUST(?P<CustNumber>\d+)\\(?P<Season>[fswu]{1})(?P<Year>\d{2})\\ (?P<TableName>[a-zA-Z0-9-_ ]+\.csv$) How can I account for either... p:\CUST100\F00\ORDERS.CSV or... p:\who\knows\how\many\subfolders\CUST100\F00\ORDERS.CSV Some explaination of what I have... ^(?P<StorageResource>(?:[a-zA-Z]{1} |(?:\\{2}[a-zA-Z0-9-_ ]+))\\ - This Searches for a single drive letter followed by a colon, or two slashes, and a computer name, and returns it as the named group "StorageResource"CUST(?P<CustNumber>\d+)\\(?P<Season>[fswu]{1})(?P<Year>\d{2})\\ - This searches for the word "CUST" followed by a string of numbers, and returns it as the group named "CustNumber" - Then searches for one of the 4 possible season codes, returns as "Season", and then searches for 2 digits, returned as the "Year" named group (?P<TableName>[a-zA-Z0-9-_ ]+\.csv$) - This searches for some string of alphanumeric characters, ending in .csv, and specifies that this must be at the end of the string... as the named group "TableName" I appreciate any help that could be offered. Regards, Tj |
|
#2
|
|||
|
|||
|
arrrrrrrrrrrggggggggggggggggggggg..........
another user on another board got me the answer... they found what I was trying to find (and nearly going bald in the process)....
All I needed was to add ".*" (any char 0 or more times) to my pattern to account for various subdirectories and such. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > Need some help finishing up my Regular Expression pattern |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|