正则表达式 匹配标签里面的值 eg:image input
2009-09-03 15:47
225 查看
Code
//得到input的values
public ArrayList GetInput(string htmlText)
{
Regex regex = new Regex("<title>(?<content>.*?)function JasonSearch()", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline);
string str = regex.Match(htmlText).Groups["content"].Value;
const string pattern = "<input [^~]*?>";
const string pattern1 = "value\\s*=\\s*((\"|\')?)(?<url>\\S+)(\"|\')?[^>]*";
ArrayList al = new ArrayList();
Match match = Regex.Match(str, pattern, RegexOptions.IgnoreCase);
while (match.Success)
{
string img = match.Value;
string imgsrc = Regex.Match(img, pattern1, RegexOptions.IgnoreCase).Result("${url}");
imgsrc = Regex.Replace(imgsrc, "\"|\'|\\>", "", RegexOptions.IgnoreCase);
al.Add(imgsrc);
match = match.NextMatch();
}
return al;
}
//得到图片的image路径
public static ArrayList GetImages(string htmlText)
{
const string pattern = "<img [^~]*?>";
const string pattern1 = "src\\s*=\\s*((\"|\')?)(?<url>\\S+)(\"|\')?[^>]*";
ArrayList al = new ArrayList();
Match match = Regex.Match(htmlText, pattern, RegexOptions.IgnoreCase); //找到img标记
while (match.Success)
{
string img = match.Value;
string imgsrc = Regex.Match(img, pattern1, RegexOptions.IgnoreCase).Result("${url}");
imgsrc = Regex.Replace(imgsrc, "\"|\'|\\>", "", RegexOptions.IgnoreCase);
al.Add(imgsrc);
match = match.NextMatch();
}
return al;
}
//得到input的values
public ArrayList GetInput(string htmlText)
{
Regex regex = new Regex("<title>(?<content>.*?)function JasonSearch()", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline);
string str = regex.Match(htmlText).Groups["content"].Value;
const string pattern = "<input [^~]*?>";
const string pattern1 = "value\\s*=\\s*((\"|\')?)(?<url>\\S+)(\"|\')?[^>]*";
ArrayList al = new ArrayList();
Match match = Regex.Match(str, pattern, RegexOptions.IgnoreCase);
while (match.Success)
{
string img = match.Value;
string imgsrc = Regex.Match(img, pattern1, RegexOptions.IgnoreCase).Result("${url}");
imgsrc = Regex.Replace(imgsrc, "\"|\'|\\>", "", RegexOptions.IgnoreCase);
al.Add(imgsrc);
match = match.NextMatch();
}
return al;
}
//得到图片的image路径
public static ArrayList GetImages(string htmlText)
{
const string pattern = "<img [^~]*?>";
const string pattern1 = "src\\s*=\\s*((\"|\')?)(?<url>\\S+)(\"|\')?[^>]*";
ArrayList al = new ArrayList();
Match match = Regex.Match(htmlText, pattern, RegexOptions.IgnoreCase); //找到img标记
while (match.Success)
{
string img = match.Value;
string imgsrc = Regex.Match(img, pattern1, RegexOptions.IgnoreCase).Result("${url}");
imgsrc = Regex.Replace(imgsrc, "\"|\'|\\>", "", RegexOptions.IgnoreCase);
al.Add(imgsrc);
match = match.NextMatch();
}
return al;
}
相关文章推荐
- php 正则表达式怎么匹配标签里面的style?
- 正则表达式匹配 a href链接,和input里面的value值
- html5的input标签的pattern正则匹配问题
- 微博内容正则表达式匹配链接, 话题标签与@用户
- 微博内容正则表达式匹配链接, 话题标签与@用户
- 微博内容正则表达式匹配链接, 话题标签与@用户
- 使用正则表达式匹配HTML 下各种<title>标签
- 匹配所有合法的HTML标签的正则表达式
- PHP正则表达式匹配嵌套HTML标签的方法和技巧
- 正则表达式运用到JSP页面(使用在input 标签内)
- (转)c# .net 使用正则表达式匹配嵌套Html标签
- !! 使用正则表达式匹配嵌套Html标签
- 正则表达式匹配标签
- (转)PHP正则表达式匹配嵌套HTML标签的方法和技巧
- 匹配html img 标签的正则表达式 java
- 正则表达式匹配所有不包含 css 的 html 标签
- 【推荐】c# .net 使用正则表达式匹配嵌套Html标签
- 微博内容正则表达式匹配链接, 话题标签与@用户
- 微博内容正则表达式匹配链接, 话题标签与@用户
- 微博内容正则表达式匹配链接, 话题标签与@用户