java 正则匹配空格字符串 正则表达式截取字符串 需求:从一堆sql中取出某些特定字符串: 比如配置的sql语句为:"company_code = @cc and project_id = @pid ; update t set a = @aa,b=@bb,c=@cd,ttt=@ttt;update t2 set d=@bb"; 我要拿出所有的以@开头的作为变量,并且去重,则如下玩: ps:其中正则匹配空格是 “\s+” public class Test { public stat
包括5种形式,如测试结果 import java.util.Scanner; import java.util.regex.*; public class Com { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String str=sc.nextLine(); Pattern p = Pattern.compile("\\d+||\\d*\\
//随机验证码,有数字.字符 //生成随机数,然后再截取,还要限定随机数的范围 String zimu = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890" ; Random rm = new Random(); //生成随机数 int a = rm.nextInt(61); //0到61之间的随机数赋值给a int b = rm.nextInt(61); int c = rm.nextInt(61); i
1.简单匹配小案例 public static void main( String[] args ){ // 按指定模式在字符串查找 String line = "This order was placed for QT3000! OK? This is OK."; String pattern = "(OK)\\?"; // 创建 Pattern 对象 Pattern r = Pattern.compile(pattern); // 现在创建 matcher 对象