C# RegEx string extraction

前端 未结 5 697
孤街浪徒
孤街浪徒 2020-12-05 06:06

I have a string:

\"ImageDimension=655x0;ThumbnailDimension=0x0\".

I have to extract first number (\"655\" string) coming in be

5条回答
  •  天涯浪人
    2020-12-05 06:47

    var m = Regex.Match(str,@"(\d+).(\d+).*?(\d+).(\d+)");
    m.Groups[1].Value; // 655 ....
    

    (\d+) 
    

    Get the first set of one or more digits. and store it as the first captured group after the entire match

    .
    

    Match any character

    (\d+)
    

    Get the next set of one or more digits. and store it as the second captured group after the entire match

    .*? 
    

    match and number of any characters in a non greedy fashion.

    (\d+)
    

    Get the next set of one or more digits. and store it as the third captured group after the entire match

    (\d+)
    

    Get the next set of one or more digits. and store it as the fourth captured group after the entire match

提交回复
热议问题