List of usage examples for java.util.regex Pattern MULTILINE
int MULTILINE
To view the source code for java.util.regex Pattern MULTILINE.
Click Source Link
From source file:Main.java
public static String delPreLocation(String regex, String content) { Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); if (matcher.find()) { return content.substring(matcher.end(), content.length()); }/*from w w w .j a v a 2s .c o m*/ return content; }
From source file:Main.java
public static <T extends Collection<String>> T findAll(String regex, String content, int group, T collection) { Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); while (matcher.find()) { collection.add(matcher.group(group)); }//from w w w .j av a2s .com return collection; }
From source file:Main.java
public static String get(String regex, String content, int groupIndex) { Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); if (matcher.find()) { return matcher.group(groupIndex); }/* w w w .j a v a 2 s . c om*/ return null; }
From source file:Main.java
/** * Match a pattern with a single capturing group and return the content of * the capturing group// w w w . j av a 2 s. c om * * @param text the text to match against * @param pattern the pattern (regular expression) must contain one and only one * capturing group * @return */ public static String matchPattern(String text, String pattern) { // Use regular expression matching to pull the min and max values from // the output of gdalinfo Pattern p1 = Pattern.compile(pattern, Pattern.MULTILINE); Matcher m1 = p1.matcher(text); if (m1.find()) { if (m1.groupCount() == 1) { return m1.group(1); } else { throw new RuntimeException("error matching pattern " + pattern); } } else { throw new RuntimeException("error matching pattern " + pattern); } }
From source file:Main.java
public static String getRootTag(String xmlStr) { Matcher m;/* www .j a v a 2s . co m*/ m = Pattern.compile("^[\r\n \t]*<.*?>[\r\n \t]*<(.*?)>", Pattern.MULTILINE | Pattern.DOTALL) .matcher(xmlStr); if (m.find()) { return m.group(1); } return ""; }
From source file:Main.java
/** * Replaces a tag given by a tagname in an xmlstring. * /*ww w .j a v a 2 s. co m*/ * @param tagname Name of the tag to be removed * @param xmlstring XmlString to be modified * @return modified XmlString */ public static String removeTag(String tagname, String xmlstring) { if (!patterns.containsKey(tagname)) { String regex = "(\\<" + tagname + ">.+?\\</" + tagname + ">)"; Pattern pattern = Pattern.compile(regex, Pattern.DOTALL | Pattern.MULTILINE); patterns.put(tagname, pattern); } Matcher matcher = patterns.get(tagname).matcher(xmlstring); if (matcher.find()) { xmlstring = matcher.replaceAll(""); } return xmlstring; }
From source file:Main.java
public static String[] getTagDataArray(String xmlStr, String xmlRoot) { List<String> data = new ArrayList<String>(); Matcher m;//from w w w . j ava 2 s . c o m m = Pattern.compile("<" + xmlRoot + ">(.*?)</" + xmlRoot + ">", Pattern.MULTILINE | Pattern.DOTALL) .matcher(xmlStr); while (m.find()) { data.add(xmlToText(m.group(1))); } return data.toArray(new String[data.size()]); }
From source file:Main.java
/** * Compiles the given regular expression into a Pattern that may or may not be case-sensitive, depending on the regular expression. * If the regular expression contains any capital letter, that is assumed to be meaningful, and the resulting Pattern is case-sensitive. * If the whole regular expression is lower-case, the resulting Pattern is case-insensitive. * // ww w . j a v a2s.c om * This is useful for implementing functionality like emacs/vim's "smart case", hence the name. * * By default, we enable (?m) on the assumption that it's more useful if ^ and $ match the start and end of each line rather than just the start and end of input. */ public static Pattern smartCaseCompile(String regularExpression) { boolean caseInsensitive = true; for (int i = 0; i < regularExpression.length(); ++i) { if (Character.isUpperCase(regularExpression.charAt(i))) { caseInsensitive = false; } } int flags = Pattern.MULTILINE; if (caseInsensitive) { flags |= Pattern.CASE_INSENSITIVE; } return Pattern.compile(regularExpression, flags); }
From source file:Main.java
/** * Pattern.pattern and Pattern.toString ignore any flags supplied to * Pattern.compile, so the regular expression you get out doesn't * correspond to what the Pattern was actually matching. This fixes that. * //from w ww.j av a 2 s. c om * Note that there are some flags that can't be represented. * * FIXME: why don't we use Pattern.LITERAL instead of home-grown escaping * code? Is it because you can't do the reverse transformation? Should we * integrate that code with this? */ public static String toString(Pattern pattern) { String regex = pattern.pattern(); final int flags = pattern.flags(); if (flags != 0) { StringBuilder builder = new StringBuilder("(?"); toStringHelper(builder, flags, Pattern.UNIX_LINES, 'd'); toStringHelper(builder, flags, Pattern.CASE_INSENSITIVE, 'i'); toStringHelper(builder, flags, Pattern.COMMENTS, 'x'); toStringHelper(builder, flags, Pattern.MULTILINE, 'm'); toStringHelper(builder, flags, Pattern.DOTALL, 's'); toStringHelper(builder, flags, Pattern.UNICODE_CASE, 'u'); builder.append(")"); regex = builder.toString() + regex; } return regex; }
From source file:Main.java
/** * Parse <xmlRoot name="this.is.name" value="this.is.value"> and return name, value * * @param xmlRoot xml tag name// ww w.j av a2 s . c om * @param xmlStr string containing xml * @return String[]{name, value} */ public static String[] getNameValue(String xmlRoot, String xmlStr) { String[] strs = new String[] { "", "" }; Matcher m; m = Pattern .compile("<" + xmlRoot + " name=\"(.*?)\" value=\"(.*?)\" />", Pattern.MULTILINE | Pattern.DOTALL) .matcher(xmlStr); if (m.find()) { strs[0] = m.group(1); strs[1] = m.group(2); } return strs; }