日期:2014-05-19  浏览次数:20841 次

请帮忙写一正则表达式
字符串: <br/> UserName:&nbsp;&nbsp;AV-6009034 <br/> Password:&nbsp;&nbsp;61fxe72opj <br/> <br/> UserName:&nbsp;&nbsp;AV-5974303 <br/> Password:&nbsp;&nbsp;p9stc1r5vb <br/> <br/> UserName:&nbsp;&nbsp;AV-6016790 <br/> Password:&nbsp;&nbsp;95hh667r9a <br/> <br/>


希望得到的结果:
m.Groups[0].Value:

UserName:       AV-6009034
Password:       61fxe72opj


m.Groups[1].Value:

UserName:       AV-5974303
Password:       p9stc1r5vb


................


------解决方案--------------------
UserName:(&nbsp;){2}(? <UserName> AV-\d{7})\ <br/\> +Password:(&nbsp;){2}(? <Password> [\w\d]{10})
m.Group[ "UserName "]
m.Group[ "Password "]
------解决方案--------------------
try

string test = " <br/> UserName:&nbsp;&nbsp;AV-6009034 <br/> Password:&nbsp;&nbsp;61fxe72opj <br/> <br/> UserName:&nbsp;&nbsp;AV-5974303 <br/> Password:&nbsp;&nbsp;p9stc1r5vb <br/> <br/> UserName:&nbsp;&nbsp;AV-6016790 <br/> Password:&nbsp;&nbsp;95hh667r9a <br/> <br/> ";
test = test.Replace( "&nbsp; ", " ");
test = test.Replace( " <br/> ", "\n ");
MatchCollection mc = Regex.Matches(test, @ "UserName:\s+\S+\s*Password:\s+\S+ ", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
richTextBox2.Text += m.Value + "\n\n ";
}