RegEx to get text within tags

后端 未结 5 1690
南旧
南旧 2021-02-06 18:51

I need a Regular Expressions to get the text within 2 tags.

Lets say I want an array returned containing any text within > and

5条回答
  •  时光说笑
    2021-02-06 19:43

    Since you specifically mentioned C#, here's how I'm doing that exact parsing:

    private static readonly Regex RgbValuePattern = new Regex(@"(?\d{1,3}) ?, ?(?\d{1,3}) ?, ?(?\d{1,3})",
                                                              RegexOptions.Compiled | RegexOptions.ExplicitCapture);
    

    Then later on...

    var match = RgbValuePattern.Match(value);
    
    if (match.Success)
    {
        int r = Int32.Parse(match.Groups["r"].Value, NumberFormatInfo.InvariantInfo);
        int g = Int32.Parse(match.Groups["g"].Value, NumberFormatInfo.InvariantInfo);
        int b = Int32.Parse(match.Groups["b"].Value, NumberFormatInfo.InvariantInfo);
        return Color.FromArgb(r, g, b);
    }
    

提交回复
热议问题