import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Hello {
public static void main(String[] args) throws Exception {
String str = "<input type=\"button\" value=\"jakcy\">";
Pattern pattern = Pattern.compile("<input type=\"(.+?)\" value=\"(.+?)\">");
Matcher matcher = pattern.matcher(str); while (matcher.find()) {
System.out.println("Value is: " + matcher.group(2));
}
}
}输出:
Value is: jakcy
import java.util.regex.Pattern;public class Hello {
public static void main(String[] args) throws Exception {
String str = "<input type=\"button\" value=\"jakcy\">";
Pattern pattern = Pattern.compile("<input type=\"(.+?)\" value=\"(.+?)\">");
Matcher matcher = pattern.matcher(str); while (matcher.find()) {
System.out.println("Value is: " + matcher.group(2));
}
}
}输出:
Value is: jakcy
这个我知道啊,我也是这么做的,测试当然会通过,但问题是你的String str中的双引号也是已经做了转义字符处理的啊,和我一楼所说的情况一样. 我的数据是从数据库中取出来的,很长的文章,里面带有双引号,并使用转义字符啊.
现在是正则表达式中加入 <input 就不行了,不知道这个 < 符号为什么不行,但反括号 > 是可以的,不知道什么原因