正则的问题
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);
}
[解决办法]
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);}