List of usage examples for java.util.regex Matcher find
public boolean find(int start)
From source file:Main.java
public static void main(String args[]) { Pattern p = Pattern.compile("test", Pattern.CASE_INSENSITIVE); String candidateString = "Test."; Matcher matcher = p.matcher(candidateString); matcher.find(0); System.out.println(matcher.group()); }
From source file:Main.java
public static void main(String args[]) { Pattern p = Pattern.compile("java", Pattern.CASE_INSENSITIVE); String candidateString = "Java. java JAVA jAVA"; Matcher matcher = p.matcher(candidateString); // display the latter match System.out.println(candidateString); matcher.find(11); System.out.println(matcher.group()); // display the earlier match System.out.println(candidateString); matcher.find(0);// w ww. j av a 2s . com System.out.println(matcher.group()); }
From source file:com.gzj.tulip.jade.statement.SystemInterpreter.java
public static void main(String[] args) throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("table", "my_table_name"); parameters.put("id", "my_id"); parameters.put(":1", "first_param"); final Pattern PATTERN = Pattern.compile("\\{([a-zA-Z0-9_\\.\\:]+)\\}|##\\((.+)\\)"); String sql = "select form ##(:table) {name} where {id}='{1}'"; StringBuilder sb = new StringBuilder(sql.length() + 200); Matcher matcher = PATTERN.matcher(sql); int start = 0; while (matcher.find(start)) { sb.append(sql.substring(start, matcher.start())); String group = matcher.group(); String key = null;//from w w w . jav a2 s . co m if (group.startsWith("{")) { key = matcher.group(1); } else if (group.startsWith("##(")) { key = matcher.group(2); } System.out.println(key); if (key == null || key.length() == 0) { continue; } Object value = parameters.get(key); // {paramName}?{:1}? if (value == null) { if (key.startsWith(":") || key.startsWith("$")) { value = parameters.get(key.substring(1)); // {:paramName} } else { char ch = key.charAt(0); if (ch >= '0' && ch <= '9') { value = parameters.get(":" + key); // {1}? } } } if (value == null) { value = parameters.get(key); // ? } if (value != null) { sb.append(value); } else { sb.append(group); } start = matcher.end(); } sb.append(sql.substring(start)); System.out.println(sb); }
From source file:Main.java
/** * /* w w w . java2 s. c o m*/ * @param tagName * @param content * @param fromIndex * @return */ public static int findTagBegin(String tagName, CharSequence content, int fromIndex) { Pattern PTN_TAG_BEGIN = Pattern.compile("<" + tagName + "[\\s>]"); Matcher matcher = PTN_TAG_BEGIN.matcher(content); if (matcher.find(fromIndex)) { return matcher.start(); } else { return -1; } }