读书人

正则的有关问题

发布时间: 2012-04-27 11:57:44 作者: rapoo

正则的问题
Your username is: afomhqm35
Your password is: Oa(RYVflc6jh
You can now log in: http://www.2date.org/

Enjoy!

请教各位怎么把上面的内容格式提取为
afomhqm35
Oa(RYVflc6jh
即,第一行保存用户名,第二行保存用户密码

[解决办法]
[^:]+:(.+)

取第一个分组
string input=@"Your username is: afomhqm35
Your password is: Oa(RYVflc6jh
You can now log in: http://www.2date.org/ ";
List<string> list=new List<string>();
foreach(Match m in Regex.Matches(input,@"[^:]+:(.+)"))
{
list.Add(m.Groups[1].Value);
}
[解决办法]

C# code
    string input=@"Your username is: afomhqm35   Your password is: Oa(RYVflc6jh   You can now log in: http://www.2date.org/ ";List<string> list=new List<string>();foreach(Match m in Regex.Matches(input,@"(?<=is:\s*)\S+")){  list.Add(m.Value);} 

读书人网 >VB Dotnet

热点推荐