正则的有关问题
正则的问题
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);
}
------解决方案--------------------
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); }