tags:

views:

117

answers:

3

I have the follow code:

string DB1 = DB1 = Regex.Match(contents, @"DB1=(?<DB1>[^\r\n]+)").Groups["DB1"].Value;

The code reads a file and looks for the following line:

DB1=Database\ABSER\ABSER

how can i modify the code that i have to exclude the 2nd \ABSER

I want my code to read only Database\ABSER , so essentially cut off the 2nd ABSER. I also need to kill this like at the \r\n. Thanks for all the help.

A: 

have a look at this link:

http://geekswithblogs.net/shahed/archive/2005/10/29/58515.aspx

Tony
A: 
DB1=(?<dbname>.*(?=\\))

This just uses a positive look ahead, its extremely brittle, and only addresses the 2nd sub-directory. A trailing slash on the second ABSER and an additional directory will break it.

RandomNoob
+1  A: 
string DB1 = DB1 = Regex.Match(contents, @"DB1=(?<DB1>.*)\\.*").Groups["DB1"].Value;

try that out.

Ragepotato