日期:2014-05-18 浏览次数:20810 次
string str = "font-size:12pt|font-family:微软雅黑|font-weight:bold|font-color:#111111|width:640px|height:120px|bgcolor:#ffffff";
font-size null 12 pt font-color # 111111 width null 120 px --……
string tempStr = "font-size:12pt|font-family:微软雅黑|font-weight:bold|font-color:#111111|width:640px|height:120px|bgcolor:#ffffff"; foreach (Match m in Regex.Matches(tempStr, pattern)) { //循环输出 string value = m.Value; string PA = m.Groups[1].Value;//font-size string PB = m.Groups[2].Value;//null string PC = m.Groups[3].Value;//12 string PD = m.Groups[4].Value;//pt }
------解决方案--------------------
string pattern = @"(?i)([^:|]+):([^|\d]*)(\d+)([^|\s]*)";
------解决方案--------------------
string str = "font-size:12pt|font-family:微软雅黑|font-weight:bold|font-color:#111111|width:640px|height:120px|bgcolor:#ffffff"; Regex reg = new Regex(@"(?is)(?<PA>[^:|]+):(?<PB>#)?(?<PC>\d+|[^\d|]+)(?<PD>p[xt])?"); foreach (Match m in reg.Matches(str)) Console.WriteLine("{0}=={1,1}=={2}=={3,2}==", m.Groups["PA"].Value, m.Groups["PB"].Value, m.Groups["PC"].Value, m.Groups["PD"].Value); /* font-size== ==12==pt== font-family== ==微软雅黑== == font-weight== ==bold== == font-color==#==111111== == width== ==640==px== height== ==120==px== bgcolor==#==ffffff== == */
------解决方案--------------------