使用正则表达式检索第二个名称 [英] Retrieve The Second Name Using Regex
本文介绍了使用正则表达式检索第二个名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Regex来检索此人及其地址。
结果如下:
所有Frank Anderson及其字符串列表中的地址。
问题:
我遇到的问题是我无法检索弗兰克安德烈安德森基于我的正则表达式。
也可能是其他人可以拥有另一个名字。
谢谢!
I want to use Regex to retrieve the person and its address.
The result wild be :
All Frank Anderson and its address inside of a string list.
Problem:
The problem I'm facing is that I cannot retrieve the second name that is "Frank Andre Anderson" based on my regex.
It also might be other people who can have another second name.
Thank you!
string pFirstname = "Frank"
string pLastname = "Anderson";
string input = w.DownloadString("http://www.birthday.no/sok/?f=Frank&l=Anderson");
Match theRegex8 = Regex.Match(input, @"(?<=\>)" + pFirstname + "(.+?)" + pLastname + "</a></h3><p><span>(.+?<)", RegexOptions.IgnoreCase);
foreach (var matchgroup in theRegex8.Groups)
{
var sss = matchgroup;
}
推荐答案
请检查以下代码并告诉我....它在我的系统中工作
string pFirstname =Frank;
string pLastname =Anderson;
string input = System.IO.File.ReadAllText(@Data.txt);
var w = new WebClient();
// string input = w.DownloadString(http://www.birthday.no/sok/?f=Frank&l=Anderson);
string pattern = pFirstname + @(\ s)(\ w)*(\ s)? + pLastname + @(\w | \s | \d |,)+;
var regex = new Regex(pattern);
/ * string str = Regex.Replace(输入,@( )|(\< b\>)|(\< \ / a\>)|(&NBSP;)|(\< \>)|(\< span\>)|(\< \ / span\>) |(\< \ / div\>)|(\< \ / b\>)|(\< \ / h3\>)|(\< ; \ / p \>)|(\< div \>)|(\< h3 \>)|(\< p \>), );(\<(\ /)?(\ w)*(\d)?\>)* /
string str = Regex.Replace(输入,@( )|(\<(\ /)?(\ w)*(\ d)?\>),);
var match = regex.Match(str);
while(match.Success)
{
Console.WriteLine(str.Substring(match.Index,match.Length));
match = match.NextMatch();
}
Console.ReadLine();
Please check the below code and let me know....it is working in my system
string pFirstname = "Frank";
string pLastname = "Anderson";
string input = System.IO.File.ReadAllText(@"Data.txt");
var w = new WebClient();
//string input = w.DownloadString("http://www.birthday.no/sok/?f=Frank&l=Anderson");
string pattern = pFirstname + @"(\s)(\w)*(\s)?" + pLastname + @"(\w|\s|\d|,)+";
var regex = new Regex(pattern);
/*string str = Regex.Replace(input, @"(�)|(\<b\>)|(\<\/a\>)|( )|(\<\>)|(\<span\>)|(\<\/span\>)|(\<\/div\>)|(\<\/b\>)|(\<\/h3\>)|(\<\/p\>)|(\<div\>)|(\<h3\>)|(\<p\>)", " ");(\<(\/)?(\w)*(\d)?\>)*/
string str = Regex.Replace(input, @"(�)|(\<(\/)?(\w)*(\d)?\>)", " ");
var match = regex.Match(str);
while (match.Success)
{
Console.WriteLine(str.Substring(match.Index,match.Length));
match = match.NextMatch();
}
Console.ReadLine();
这篇关于使用正则表达式检索第二个名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文