tags:

views:

45

answers:

3
+1  Q: 

Regex Question..

Hello everyone-

In my C# Console App I'm trying to use Regex to search a string to determine if there is a match or not. Below is my code but it is not quite working right so I will explain further. sSearchString is set to "_One-Call_Pipeline_Locations" and pDS.Name is a filename it is searching against. Using the code below it is set to true for Nevada_One-Call_Pipeline_Locations and Nevada_One-Call_Pipeline_LocationsMAXIMUM. There should be a match for Nevada_One-Call_Pipeline_Locations But Not for Nevada_One-Call_Pipeline_LocationsMAXIMUM. How can I change my code to do this properly?

Thanks in advance

if (Regex.IsMatch(pDS.Name, sSearchString))
+2  A: 

change the sSearchString to ".*_One-Call_Pipeline_Locations$"

jpabluz
+1  A: 

You need to specify that a matching name must end with the text you have entered using the dollar token.

sSearchString = "_One-Call_Pipeline_Locations$";
David M
A: 

Since you provided no details as to what else should match, we can only assume that if the string ends with "Nevada_One-Call_Pipeline_Locations", then it matches? Is this correct?

If so, you don't need Regex:

if (pDS.Name.EndsWith("Nevada_One-Call_Pipeline_Locations"))
{ //...
John Rasch
I only provided those two as examples. there is a lot of other strings that will be searched against sSearchString
Josh