当前位置:编程学习 > JAVA >>

求正则,发自真心。。。谢谢各位

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里全局搜索,所以需要使用在搜索里可以用的正则表达式 --------------------编程问答-------------------- ^(?!hello)[a-zA-Z\/]{1+}$
你试试吧。我不确定
不行再告诉我我再改改 --------------------编程问答--------------------

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());
}

--------------------编程问答-------------------- <img\b[^>]*?alt=(['"]?)(?!hello)[a-zA-Z]+\1[^>]*?> --------------------编程问答-------------------- 除
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,