List of usage examples for java.util.regex Pattern DOTALL
int DOTALL
To view the source code for java.util.regex Pattern DOTALL.
Click Source Link
From source file:Main.java
public static void main(String[] args) { Pattern p = Pattern.compile("<row><column>(.*)</column></row>", Pattern.DOTALL); Matcher matcher = p.matcher("<row><column>Header\n\n\ntext</column></row>"); if (matcher.matches()) { System.out.println(matcher.group(1)); }// ww w . j av a 2 s .c om }
From source file:Main.java
public static void main(String[] argv) throws Exception { CharSequence inputStr = "abc\ndef"; String patternStr = ".*c.+d.*"; Pattern pattern = Pattern.compile(patternStr, Pattern.DOTALL); Matcher matcher = pattern.matcher(inputStr); boolean matchFound = matcher.matches(); matchFound = pattern.matches(".*c.+d.*", "abc\r\ndef"); matchFound = pattern.matches("(?s).*c.+d.*", "abc\r\ndef"); }
From source file:TheReplacements.java
public static void main(String[] args) throws Exception { String s = TextFile.read("TheReplacements.java"); // Match the specially-commented block of text above: Matcher mInput = Pattern.compile("/\\*!(.*)!\\*/", Pattern.DOTALL).matcher(s); if (mInput.find()) s = mInput.group(1); // Captured by parentheses // Replace two or more spaces with a single space: s = s.replaceAll(" {2,}", " "); // Replace one or more spaces at the beginning of each // line with no spaces. Must enable MULTILINE mode: s = s.replaceAll("(?m)^ +", ""); System.out.println(s);//from w ww .j ava2 s . co m s = s.replaceFirst("[aeiou]", "(VOWEL1)"); StringBuffer sbuf = new StringBuffer(); Pattern p = Pattern.compile("[aeiou]"); Matcher m = p.matcher(s); // Process the find information as you // perform the replacements: while (m.find()) m.appendReplacement(sbuf, m.group().toUpperCase()); // Put in the remainder of the text: m.appendTail(sbuf); System.out.println(sbuf); }
From source file:NLMatch.java
public static void main(String[] argv) { String input = "I dream of engines\nmore engines, all day long"; System.out.println("INPUT: " + input); System.out.println();//from ww w .ja va 2 s .c o m String[] patt = { "engines.more engines", "engines$" }; for (int i = 0; i < patt.length; i++) { System.out.println("PATTERN " + patt[i]); boolean found; Pattern p1l = Pattern.compile(patt[i]); found = p1l.matcher(input).find(); System.out.println("DEFAULT match " + found); Pattern pml = Pattern.compile(patt[i], Pattern.DOTALL | Pattern.MULTILINE); found = pml.matcher(input).find(); System.out.println("MultiLine match " + found); System.out.println(); } }
From source file:nl.meertens.cmdi.FindProfiles.java
public static void main(String[] args) throws FileNotFoundException { Boolean debug = false;//from ww w . j a v a 2 s .c om Boolean verbose = false; String dir = "."; String ext = "cmdi"; // check command line OptionParser parser = new OptionParser("dve:?*"); OptionSet options = parser.parse(args); if (options.has("d")) debug = true; if (options.has("v")) verbose = true; if (options.has("e")) ext = (String) options.valueOf("e"); if (options.has("?")) { showHelp(); System.exit(0); } List arg = options.nonOptionArguments(); if (arg.size() > 1) { System.err.println("!FTL: only one source <DIR> argument is allowed!"); showHelp(); System.exit(1); } if (arg.size() == 1) dir = (String) arg.get(0); Set<String> profiles = new HashSet<String>(); Pattern cr_rest = Pattern.compile("^.*" + CR_URI + "rest/registry/profiles/", Pattern.DOTALL); Pattern cr_ext = Pattern.compile("/xsd.*$", Pattern.DOTALL); XMLInputFactory2 xmlif = (XMLInputFactory2) XMLInputFactory2.newInstance(); xmlif.configureForConvenience(); Collection<File> inputs = FileUtils.listFiles(new File(dir), new String[] { ext }, true); int e = 0; int i = 0; int s = inputs.size(); for (File input : inputs) { i++; if (verbose) System.err.println("?INF: " + i + "/" + s + ": " + input); int state = START; int sdepth = 0; int depth = 0; XMLStreamReader2 xmlr = null; FileInputStream in = null; String profile = null; try { in = new FileInputStream(input); xmlr = (XMLStreamReader2) xmlif.createXMLStreamReader(in); while (state != STOP && state != ERROR) { int eventType = xmlr.getEventType(); QName qn = null; switch (eventType) { case XMLEvent2.START_ELEMENT: depth++; qn = xmlr.getName(); break; case XMLEvent2.END_ELEMENT: qn = xmlr.getName(); break; } switch (state) { case START: switch (eventType) { case XMLEvent2.START_ELEMENT: if (qn.getNamespaceURI().equals(CMD_NS) && qn.getLocalPart().equals("CMD")) { state = OPEN_CMD; sdepth = depth; String prof = xmlr.getAttributeValue(XSI_NS, "schemaLocation"); if (prof != null) { if (prof.contains(CR_URI)) { prof = cr_rest.matcher(prof).replaceFirst(""); prof = cr_ext.matcher(prof).replaceFirst(""); profile = prof; if (verbose || debug) System.out.println("?" + (debug ? "DBG" : "INF") + ": " + input + ": xsi:schemaLocation[" + prof + "]"); } else System.err.println("!WRN: " + input + ": xsi:schemaLocation[" + prof + "] doesn't contain a reference to a CMD profile in CR!"); } } else { System.err.println("!ERR: " + input + ": no cmd:CMD root found!"); state = ERROR; } break; case XMLEvent2.END_DOCUMENT: System.err.println("!ERR: " + input + ": no XML content found!"); state = ERROR; break; } break; case OPEN_CMD: switch (eventType) { case XMLEvent2.START_ELEMENT: if (qn.getNamespaceURI().equals(CMD_NS) && qn.getLocalPart().equals("Header")) { state = OPEN_HEADER; sdepth = depth; } else { System.err.println("!ERR: " + input + ": no cmd:CMD/cmd:Header found!"); state = ERROR; } break; case XMLEvent2.END_ELEMENT: if (qn.getNamespaceURI().equals(CMD_NS) && qn.getLocalPart().equals("CMD") && sdepth == depth) { System.err.println("!ERR: " + input + ": no cmd:CMD/cmd:Header found!"); state = ERROR; } break; } break; case OPEN_HEADER: switch (eventType) { case XMLEvent2.START_ELEMENT: if (qn.getNamespaceURI().equals(CMD_NS) && qn.getLocalPart().equals("MdProfile") && sdepth + 1 == depth) { state = OPEN_MDPROFILE; } break; case XMLEvent2.END_ELEMENT: if (qn.getNamespaceURI().equals(CMD_NS) && qn.getLocalPart().equals("Header") && sdepth == depth) { System.err.println("!" + (profile == null ? "ERR" : "WRN") + ": " + input + ": no cmd:CMD/cmd:Header/cmd:MdProfile found!"); state = ERROR; } break; } break; case OPEN_MDPROFILE: switch (eventType) { case XMLEvent2.CHARACTERS: String prof = xmlr.getText(); prof = cr_rest.matcher(prof).replaceFirst(""); prof = cr_ext.matcher(prof).replaceFirst(""); if (verbose || debug) System.out.println( "?" + (debug ? "DBG" : "INF") + ": " + input + ": MdProfile[" + prof + "]"); if (profile == null) profile = prof; else if (!prof.equals(profile)) System.out.println("!WRN: " + input + ": MdProfile[" + prof + "] and xsi:schemaLocation[" + profile + "] contradict!"); state = STOP; break; default: state = STOP; break; } break; } switch (eventType) { case XMLEvent2.END_ELEMENT: depth--; break; } eventType = xmlr.next(); } } catch (Exception ex) { System.err.println("!ERR: " + input + ": " + ex); ex.printStackTrace(System.err); state = ERROR; } finally { try { xmlr.close(); in.close(); } catch (Exception ex) { System.err.println("!ERR: " + input + ": " + ex); ex.printStackTrace(System.err); state = ERROR; } } if (profile != null) profiles.add(profile); if (state == ERROR) e++; } for (String profile : profiles) { System.out.println(profile); } System.exit(e); }
From source file:core.plugin.mybatis.PageInterceptor.java
public static void main(String[] args) { List<String> tests = new ArrayList<String>(); tests.add("select count(*) from abc \n\t\t where\n abc"); tests.add("SELECT COUNT(*) from abc"); tests.add(" select count (*) from abc"); tests.add(" select count( *) from abc"); tests.add("select count( * ),id from abc"); tests.add("select * from abc"); tests.add("select abc,test,fdas from abc"); tests.add("select count(adb) from abc"); tests.add("select count(0) from abc"); tests.add("select min(count(*)) from abc"); tests.add("update min(count(*)) from abc"); tests.add("delete min(count(*)) from abc"); Pattern p1 = Pattern.compile(SQL_SELECT_REGEX, Pattern.DOTALL | Pattern.CASE_INSENSITIVE); Pattern p2 = Pattern.compile(SQL_COUNT_REGEX, Pattern.DOTALL | Pattern.CASE_INSENSITIVE); for (String str : tests) { Matcher m1 = p1.matcher(str); Matcher m2 = p2.matcher(str); System.out.println("?: " + str); System.out.println(" select?? " + m1.matches()); System.out.println(" count?? " + m2.matches()); System.out.println();/*from w w w . j a va 2 s . c o m*/ } }
From source file:Main.java
public static String getContentMathML(String latexMLResponse) { String CML_REGEX = "<annotation-xml.*MWS-Query\">(.*)<.annotation-xml>"; Pattern pattern = Pattern.compile(CML_REGEX, Pattern.DOTALL); try {/*w w w .j a va 2s . c o m*/ JSONObject latexMLJSON = new JSONObject(latexMLResponse); String math = latexMLJSON.getString("result"); Matcher matcher = pattern.matcher(math); if (matcher.find()) { return matcher.group(1); } } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static ArrayList<Pattern> createArrayListPFromStringArray(final String[] regexArray) { final ArrayList<Pattern> returnPatternsList = new ArrayList<Pattern>(); for (int j = 0; j < regexArray.length; j++) { returnPatternsList.add(Pattern.compile(regexArray[j], Pattern.DOTALL)); }/*from w w w . j a v a2s . c o m*/ return new ArrayList<Pattern>(Collections.unmodifiableList(returnPatternsList)); }
From source file:Main.java
@Nullable static String extractClientSecretFromHtml(@NonNull String html) { // quotes around attribute values are optional in HTML5: http://stackoverflow.com/q/6495310/504611 Pattern clientSecretPattern = Pattern.compile( "^.*<meta[ ]+name=['\"]?env-clientSecret['\"]?[ ]+content=['\"]?([^'\"]+)['\"]?.*$", Pattern.DOTALL); Matcher matcher = clientSecretPattern.matcher(html); String clientSecret = null;/*from w w w. j av a2s. c o m*/ if (matcher.matches()) { clientSecret = matcher.group(1); } return clientSecret; }
From source file:Main.java
/** * Regex matcher for PART X pattern in multi-part videos * http://txt2re.com/index-java.php3/*w w w . jav a 2 s. c om*/ * * @param token * @return */ @SuppressLint("DefaultLocale") private static boolean isMultiPartSeries(String token) { String re1 = "(PART)"; // Word 1 String re2 = "( )"; // White Space 1 String re3 = "(\\d+)"; // Integer Number 1 Pattern p = Pattern.compile(re1 + re2 + re3, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(token.toUpperCase()); return m.find(); }