1.<img src="images/bottom.jpg" alt="bottom" width="620" height="324" />
2.<img src="images/bottom.jpg" alt="hello.jpg" width="620" height="324" />
如上 我相匹配一下HTML中的 img符合一下三个条件的
1.alt的名称是英文
2.不是图片名称的(如1)
3.alt不等于"hello"的
4.alt 不为空
请问正则可以实现么,如果可以实现请问如何写呢?
我是想在dreamweaver里全局搜索,所以需要使用在搜索里可以用的正则表达式
2.<img src="images/bottom.jpg" alt="hello.jpg" width="620" height="324" />
如上 我相匹配一下HTML中的 img符合一下三个条件的
1.alt的名称是英文
2.不是图片名称的(如1)
3.alt不等于"hello"的
4.alt 不为空
请问正则可以实现么,如果可以实现请问如何写呢?
我是想在dreamweaver里全局搜索,所以需要使用在搜索里可以用的正则表达式
你试试吧。我不确定
不行再告诉我我再改改
String html = "<img src=\"images/bottom.jpg\" alt=\"bottom\" width=\"620\" height=\"324\" />" +
"<img src=\"images/bottom.jpg\" alt=\"hello\" width=\"620\" height=\"324\" />" +
"<img src=\"images/bottom.jpg\" alt=\"bbbhello\" width=\"620\" height=\"324\" />" +
"<img src=\"images/bottom.jpg\" alt=\"helloaaa\" width=\"620\" height=\"324\" />" +
"<img src=\"images/bottom.jpg\" width=\"620\" height=\"324\" />" +
"<img src=\"images/bottom.jpg\" alt=\"\" width=\"620\" height=\"324\" />" +
"<img src=\"images/bottom.jpg\" alt=\"hello.jpg\" width=\"620\" height=\"324\" />";
String regex = "<img[^>]+?(?!alt=\"hello\")alt=\"[a-z]+\"[^>]+>";
Pattern p = Pattern.compile(regex);
Matcher matcher = p.matcher(html);
while (matcher.find()) {
System.out.println(matcher.group());
}