List of usage examples for java.util.regex Pattern LITERAL
int LITERAL
To view the source code for java.util.regex Pattern LITERAL.
Click Source Link
From source file:Main.java
/** * Checks if a View matches a certain string and returns the amount of total matches. * /*from w ww .j a v a 2 s .c o m*/ * @param regex the regex to match * @param view the view to check * @param uniqueTextViews set of views that have matched * @return number of total matches */ public static int getNumberOfMatches(String regex, TextView view, Set<TextView> uniqueTextViews) { if (view == null) { return uniqueTextViews.size(); } Pattern pattern = null; try { pattern = Pattern.compile(regex); } catch (PatternSyntaxException e) { pattern = Pattern.compile(regex, Pattern.LITERAL); } Matcher matcher = pattern.matcher(view.getText().toString()); if (matcher.find()) { uniqueTextViews.add(view); } if (view.getError() != null) { matcher = pattern.matcher(view.getError().toString()); if (matcher.find()) { uniqueTextViews.add(view); } } if (view.getText().toString().equals("") && view.getHint() != null) { matcher = pattern.matcher(view.getHint().toString()); if (matcher.find()) { uniqueTextViews.add(view); } } return uniqueTextViews.size(); }
From source file:mergedoc.core.PatternCache.java
/** * Pattern ????/*w ww . j ava2 s . co m*/ * ? target ???????? Pattern ???? * * <p>?<br> * target ???????? Pattern ? * ???????????????? * * @param target * @return Pattern */ public static Pattern getLiteralPattern(String target) { Pattern pattern = literalCache.get(target); if (pattern == null) { pattern = Pattern.compile(target, Pattern.LITERAL); literalCache.put(target, pattern); } return pattern; }
From source file:org.apache.ofbiz.base.util.StringUtil.java
private static Map<String, Pattern> createSubstitutionPatternMap() { Map<String, Pattern> substitutionPatternMap = new LinkedHashMap<String, Pattern>(); // Preserve insertion order substitutionPatternMap.put("&&", Pattern.compile("@and", Pattern.LITERAL)); substitutionPatternMap.put("||", Pattern.compile("@or", Pattern.LITERAL)); substitutionPatternMap.put("<=", Pattern.compile("@lteq", Pattern.LITERAL)); substitutionPatternMap.put(">=", Pattern.compile("@gteq", Pattern.LITERAL)); substitutionPatternMap.put("<", Pattern.compile("@lt", Pattern.LITERAL)); substitutionPatternMap.put(">", Pattern.compile("@gt", Pattern.LITERAL)); return Collections.unmodifiableMap(substitutionPatternMap); }
From source file:org.faster.util.Strings.java
public static Pattern getPattern(String uncompiledPattern, boolean regex) { String key = uncompiledPattern + regex; Pattern pattern = patternMap.get(key); if (pattern == null) { synchronized (patternMap) { pattern = patternMap.get(key); if (pattern == null) { if (regex) { pattern = Pattern.compile(uncompiledPattern, Pattern.MULTILINE); } else { pattern = Pattern.compile(uncompiledPattern, Pattern.LITERAL); }/* w ww . ja v a 2 s .co m*/ patternMap.put(key, pattern); } } } return pattern; }
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 = ""; }/*from www . j ava2 s . com*/ 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.nuxeo.ecm.web.resources.wro.processor.FlavorResourceProcessor.java
@Override protected void process(final Resource resource, final Reader reader, final Writer writer, String flavorName) throws IOException { final InputStream is = new ProxyInputStream(new ReaderInputStream(reader, getEncoding())) { };//from w ww. ja va2 s .c o m final OutputStream os = new ProxyOutputStream(new WriterOutputStream(writer, getEncoding())); try { Map<String, String> presets = null; if (flavorName != null) { ThemeStylingService s = Framework.getService(ThemeStylingService.class); presets = s.getPresetVariables(flavorName); } if (presets == null || presets.isEmpty()) { IOUtils.copy(is, os); } else { String content = IOUtils.toString(reader); for (Map.Entry<String, String> preset : presets.entrySet()) { content = Pattern.compile("\"" + preset.getKey() + "\"", Pattern.LITERAL).matcher(content) .replaceAll(Matcher.quoteReplacement(preset.getValue())); } writer.write(content); writer.flush(); } is.close(); } catch (final Exception e) { log.error("Error while serving resource " + resource.getUri(), e); throw WroRuntimeException.wrap(e); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } }
From source file:org.nuxeo.theme.styling.wro.FlavorResourceProcessor.java
protected void process(final Resource resource, final Reader reader, final Writer writer, String flavorName) throws IOException { final InputStream is = new ProxyInputStream(new ReaderInputStream(reader, getEncoding())) { };// ww w . j a v a2s . co m final OutputStream os = new ProxyOutputStream(new WriterOutputStream(writer, getEncoding())); try { Map<String, String> presets = null; if (flavorName != null) { ThemeStylingService s = Framework.getService(ThemeStylingService.class); presets = s.getPresetVariables(flavorName); } if (presets == null || presets.isEmpty()) { IOUtils.copy(is, os); } else { String content = IOUtils.toString(reader); for (Map.Entry<String, String> preset : presets.entrySet()) { content = Pattern.compile(String.format("\"%s\"", preset.getKey()), Pattern.LITERAL) .matcher(content).replaceAll(Matcher.quoteReplacement(preset.getValue())); } writer.write(content); writer.flush(); } is.close(); os.close(); } catch (final Exception e) { throw WroRuntimeException.wrap(e); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } }
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 {/*from ww w .java 2 s . c o m*/ throw new IllegalArgumentException("Unknown flag: " + flag); } } return flagsToUse; }
From source file:pl.otros.logview.gui.message.pattern.PropertyPatternMessageColorizer.java
public void init(InputStream in) throws ConfigurationException { propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.setDelimiterParsingDisabled(true); propertiesConfiguration.load(in, "UTF-8"); configuration = new DataConfiguration(propertiesConfiguration); configuration.setDelimiterParsingDisabled(true); String pa = configuration.getString(PROP_PATTERN); int flags = 0; flags = flags | (configuration.getBoolean(PROP_PATTERN_CANON_EQ, false) ? Pattern.CANON_EQ : 0); flags = flags/* w ww .j a v a 2 s . c o m*/ | (configuration.getBoolean(PROP_PATTERN_CASE_INSENSITIVE, false) ? Pattern.CASE_INSENSITIVE : 0); flags = flags | (configuration.getBoolean(PROP_PATTERN_COMMENTS, false) ? Pattern.COMMENTS : 0); flags = flags | (configuration.getBoolean(PROP_PATTERN_DOTALL, false) ? Pattern.DOTALL : 0); flags = flags | (configuration.getBoolean(PROP_PATTERN_LITERAL, false) ? Pattern.LITERAL : 0); flags = flags | (configuration.getBoolean(PROP_PATTERN_MULTILINE, false) ? Pattern.MULTILINE : 0); flags = flags | (configuration.getBoolean(PROP_PATTERN_UNICODE_CASE, false) ? Pattern.UNICODE_CASE : 0); flags = flags | (configuration.getBoolean(PROP_PATTERN_UNIX_LINES, false) ? Pattern.UNIX_LINES : 0); pattern = Pattern.compile(pa, flags); groupCount = countGroups(pattern); name = configuration.getString(PROP_NAME, "NAME NOT SET!"); description = configuration.getString(PROP_DESCRIPTION, "DESCRIPTION NOT SET!"); testMessage = configuration.getString(PROP_TEST_MESSAGE, ""); version = configuration.getInt(PROP_VERSION, 1); }
From source file:org.opencastproject.capture.impl.XProperties.java
/** * Wrapper around the actual search and replace functionality. This function will value with all of the instances of * subkey replaced./* w ww. j a v a 2s.com*/ * * @param value * The original string you wish to replace. * @param subkey * The substring you wish to replace. This must be the substring rather than the full variable - M2_REPO * rather than ${M2_REPO} * @return The value string with all instances of subkey replaced, or null in the case of an error. */ private String findReplacement(String value, String subkey) { if (subkey == null) { return null; } Pattern p = Pattern.compile(START_REPLACEMENT + subkey + END_REPLACEMENT, Pattern.LITERAL); String replacement = null; if (System.getProperty(subkey) != null) { replacement = System.getProperty(subkey); } else if (this.getProperty(subkey) != null) { replacement = this.getProperty(subkey); } else if (this.context != null && this.bundle != null && this.bundle.getState() == Bundle.ACTIVE && this.context.getProperty(subkey) != null) { replacement = this.context.getProperty(subkey); } else if (System.getenv(subkey) != null) { replacement = System.getenv(subkey); } if (replacement != null) return p.matcher(value).replaceAll(Matcher.quoteReplacement(replacement)); else return null; }