jQuery("#checker").click(function(){
jQuery("#mydiv :checkbox").each(function(){
this.checked = true;
});
});
jQuery("#dechecker").click(function(){
jQuery("#mydiv :checkbox").each(function(){
this.checked = false;
});
});
jQuery("#checktoggler").click(function(){
jQuery("#mydiv :checkbox").each(function(){
this.checked = !this.checked;
});
});
;)
One possibility:
String imgRegex = "<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
is a possibility (if matched case-insensitively). It's a bit of a mess, and deliberately ignores the case where quotes aren't used. To represent it without worrying about string escapes:
<img[^>]+src\s*=\s*['"]([^'"]+)['"][^>]*>
This matches:
![]()
>
(i.e. possible other attributes)src
=
'
or "
>
(more possible attributes)>
to close the tagThings to note:
src=
as well, move the open bracket further left :-)>
or image sources that include '
or "
).Здесь часто возникает этот вопрос
Регулярные выражения - плохой способ решения этой проблемы. Сделайте себе одолжение и воспользуйтесь каким-нибудь парсером HTML.
Регулярные выражения плохо подходят для синтаксического анализа HTML. Вы получите сложное выражение, которое будет вести себя неожиданно в некоторых угловых случаях, что будет в противном случае.
Изменить: Если ваш HTML такой простой, то:
Pattern p = Pattern.compile("src\\s*=\\s*([\\"'])?([^ \\"']*)");
Matcher m = p.matcher(str);
if (m.find()) {
String src = m.group(2);
}
И существует любое количество парсеров Java HTML .
You mean the src-attribute of the img-Tag? In that case you can go with the following:
<[Ii][Mm][Gg]\\s*([Ss][Rr][Cc]\\s*=\\s*[\"'].*?[\"'])
That should work. The expression src='...' is in parantheses, so it is a matcher-group and can be processed separately.