List of usage examples for java.util.regex Pattern UNIX_LINES
int UNIX_LINES
To view the source code for java.util.regex Pattern UNIX_LINES.
Click Source Link
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. * // w w w .j a v a 2 s . co m * 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:com.groupon.jenkins.dynamic.buildconfiguration.ShellCommands.java
public Pattern regexp(String re) { int n = re.length() - 1, flags = Pattern.UNIX_LINES | Pattern.MULTILINE; if (re.charAt(0) != '^') { re = ".*" + re; }// w w w.j a v a2 s .co m if (re.charAt(n) != '$') { re = re + ".*"; } return Pattern.compile(re, flags); }
From source file:com.google.code.configprocessor.processing.ModifyAction.java
protected int parseFlags() { int flagsToUse = 0; String flagsToTest = getFlags() == null ? DEFAULT_PATTERN_FLAGS : getFlags(); String[] flagArray = StringUtils.split(flagsToTest, PATTERN_FLAG_SEPARATOR); for (String flag : flagArray) { if ("UNIX_LINES".equals(flag)) { flagsToUse |= Pattern.UNIX_LINES; } else if ("CASE_INSENSITIVE".equals(flag)) { flagsToUse |= Pattern.CASE_INSENSITIVE; } else if ("COMMENTS".equals(flag)) { flagsToUse |= Pattern.COMMENTS; } else if ("MULTILINE".equals(flag)) { flagsToUse |= Pattern.MULTILINE; } else if ("LITERAL".equals(flag)) { flagsToUse |= Pattern.LITERAL; } else if ("DOTALL".equals(flag)) { flagsToUse |= Pattern.DOTALL; } else if ("UNICODE_CASE".equals(flag)) { flagsToUse |= Pattern.UNICODE_CASE; } else if ("CANON_EQ".equals(flag)) { flagsToUse |= Pattern.CANON_EQ; } else {/*w w w .ja va2 s. c o m*/ throw new IllegalArgumentException("Unknown flag: " + flag); } } return flagsToUse; }
From source file:lv.vizzual.numuri.service.operators.LVDataProvider.java
private String extractNetworkProvider(String page) { String provider = null;/*from ww w .j a va 2s . co m*/ if (page.contains("Mintes laik? var veikt tikai 5 pieprasjumus!")) { throw new RequestLimitReachedException(); } String exp = "Pakalpojuma nodroin?t?js </td><td><b>(.*?)</b>"; Pattern pattern = Pattern.compile(exp, Pattern.DOTALL | Pattern.UNIX_LINES); Matcher matcher = pattern.matcher(page); if (matcher.find()) { String providerHTML = matcher.group(1); provider = Html.fromHtml(providerHTML).toString(); } return cleanNetworkProvider(provider); }
From source file:com.groupon.jenkins.buildtype.util.shell.ShellCommands.java
public Pattern regexp(String re) { final int n = re.length() - 1; final int flags = Pattern.UNIX_LINES | Pattern.MULTILINE; if (re.charAt(0) != '^') { re = ".*" + re; }/* w w w. ja v a 2 s .c om*/ if (re.charAt(n) != '$') { re = re + ".*"; } return Pattern.compile(re, flags); }
From source file:com.ikanow.aleph2.enrichment.utils.services.SimpleRegexFilterService.java
/** * Converts a string of regex flags into a single int representing those * flags for using in the java Pattern object * //from ww w. j ava 2 s . co m * @param flagsStr * @return */ public static int parseFlags(final String flagsStr) { int flags = 0; for (int i = 0; i < flagsStr.length(); ++i) { switch (flagsStr.charAt(i)) { case 'i': flags |= Pattern.CASE_INSENSITIVE; break; case 'x': flags |= Pattern.COMMENTS; break; case 's': flags |= Pattern.DOTALL; break; case 'm': flags |= Pattern.MULTILINE; break; case 'u': flags |= Pattern.UNICODE_CASE; break; case 'd': flags |= Pattern.UNIX_LINES; break; } } return flags; }
From source file:com.ikanow.infinit.e.harvest.enrichment.custom.UnstructuredAnalysisHarvester.java
private static Pattern createRegex(String regEx, String flags) { int nflags = 0; if (null != flags) { for (int i = 0; i < flags.length(); ++i) { char c = flags.charAt(i); switch (c) { case 'm': nflags |= Pattern.MULTILINE; break; case 'i': nflags |= Pattern.CASE_INSENSITIVE; break; case 'd': nflags |= Pattern.DOTALL; break; case 'u': nflags |= Pattern.UNICODE_CASE; break; case 'n': nflags |= Pattern.UNIX_LINES; break; }/*w ww.jav a2 s . c o m*/ } } return Pattern.compile(regEx, nflags); }
From source file:nz.net.orcon.kanban.automation.actions.RegexAction.java
public String extract(String text, String expressionString, int match, int group, String options) throws IOException { if (text == null) { text = ""; }// ww w . j a v a 2 s.c o m if (expressionString == null) { throw new IllegalArgumentException( "No Regular Expression has been provided to carry out this operation."); } int optionsInEffect = 0; if (options != null) { for (String option : options.toUpperCase().split("\\|")) { optionsInEffect |= (option.equals("CANON_EQ")) ? Pattern.CANON_EQ : (option.equals("CASE_INSENSITIVE")) ? Pattern.CASE_INSENSITIVE : (option.equals("COMMENTS")) ? Pattern.COMMENTS : (option.equals("DOTALL")) ? Pattern.DOTALL : (option.equals("LITERAL")) ? Pattern.LITERAL : (option.equals("MULTILINE")) ? Pattern.MULTILINE : (option.equals("UNICODE_CASE")) ? Pattern.UNICODE_CASE : (option.equals("UNIX_LINES")) ? Pattern.UNIX_LINES : 0; } } Pattern expression = Pattern.compile(expressionString, optionsInEffect); Matcher matches = expression.matcher(text); int matchIndex = 1; while (matches.find()) { for (int groupIndex = 0; matches.groupCount() + 1 > groupIndex; groupIndex++) { if (matchIndex == match && groupIndex == group) { return matches.group(groupIndex); } } matchIndex++; } return ""; }
From source file:org.apache.nifi.processors.standard.EvaluateRegularExpression.java
int getCompileFlags(ProcessContext context) { int flags = (context.getProperty(UNIX_LINES).asBoolean() ? Pattern.UNIX_LINES : 0) | (context.getProperty(CASE_INSENSITIVE).asBoolean() ? Pattern.CASE_INSENSITIVE : 0) | (context.getProperty(COMMENTS).asBoolean() ? Pattern.COMMENTS : 0) | (context.getProperty(MULTILINE).asBoolean() ? Pattern.MULTILINE : 0) | (context.getProperty(LITERAL).asBoolean() ? Pattern.LITERAL : 0) | (context.getProperty(DOTALL).asBoolean() ? Pattern.DOTALL : 0) | (context.getProperty(UNICODE_CASE).asBoolean() ? Pattern.UNICODE_CASE : 0) | (context.getProperty(CANON_EQ).asBoolean() ? Pattern.CANON_EQ : 0) | (context.getProperty(UNICODE_CHARACTER_CLASS).asBoolean() ? Pattern.UNICODE_CHARACTER_CLASS : 0); return flags; }