Quantcast
Channel: CodeProject Latest postings for Regular Expressions
Viewing all articles
Browse latest Browse all 224

RegEx Problem

$
0
0
I have this string:
 
var Line = "Dev: 0 Model: TOSHIBA MK3265GSX Serial: 20FDF20WS FW: GJ002H STW: 0 MaxLBA: 625142447 FDESUPPORTED: 0 PREBOOT: 0 DRIVETRUSTENABLED: 0 DRIVETRUSTSUPPORTED: 0 w128: 41 FULLFW: GJ002H SERVOFW: SDLSUPPORTED: 1 PLATFORM: 0 SAFE: 1 DSTTIMEOUT: 103 ISBOOTORSYSTEM: 1";
 
I am trying to use RegEx to extract all Key/Value pairs. So far I have:
 
privatestatic string getWord(ref string Line, string WordToFind)
{
var retVal = string.Empty;
 
if (Line.Contains(WordToFind))
{
    var expression = @"(?:(?'Key'\S+): (?'Value'.*?)) ";
    Match match = Regex.Match(Line, expression,RegexOptions.IgnoreCase);
 
    if (match.Success)
    {
        string key = match.Groups[1].ToString();
    }
}
 
return retVal;
}
 
 
When I pass in "Model:" I get back "Dev". What am I doing wrong here?
If it's not broken, fix it until it is

Viewing all articles
Browse latest Browse all 224

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>