Reputation: 1911
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))
Upvotes: 1
Views: 84
Reputation: 63485
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"))
{ //...
Upvotes: 0
Reputation: 72930
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$";
Upvotes: 1