I have a string looking something like this
string myString = "Master Language=\"C#\" MasterPageFile=\"~/masterpages/Libraries.master\"";
- I need to verify that it contain the exact words Master and Language=”C#”
- I cannot always guarantee that the words Master and Language will be placed like this, hence stuff like Contains(“Master Language”) wont do
I’ve been playing around with regex.IsMatch without any results for a while so if anyone could be able to help me I’d appreciate that!
Since you need to find the occurrences of the word in any order, you can use the following pattern:
This uses positive look-arounds to check for the existence of
MasterandLanguage="C#". Notice the use of the word-boundary meta-character,\b, which ensures that “Master” is an exact match. That ensures that a partial match in “MasterPage” won’t occur.Example: