I have following string
string s=@"\Users\Public\Roaming\Intel\Wireless\Settings";
I want output string like
string output="Wireless";
Sub-string what I want should be after "Intel\" and it should ends with the first "\" after "Intel\" before string Intel
and after Intel
the string may be different. I have achieved it using string.substring() but I want to get it using regular expression ? what regular expression should I write to get that string.
With regex, it will look like
var txt = @"\Users\Public\Roaming\Intel\Wireless\Settings";
var res = Regex.Match(txt, @"Intel\\([^\\]+)", RegexOptions.IgnoreCase).Groups[1].Value;
But usually, you should use string methods with such requirements. Here is a demo code (without error checking):
var strt = txt.IndexOf("Intel\\") + 6; // 6 is the length of "Intel\"
var end = txt.IndexOf("\\", strt + 1); // Look for the next "\"
var res2 = txt.Substring(strt, end - strt); // Get the substring
See IDEONE demo
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments