Java Code Examples for com.google.re2j.Matcher#replaceAll()
The following examples show how to use
com.google.re2j.Matcher#replaceAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GempakParameterTable.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Get the input stream to the given resource * * @param resourceName The resource name. May be a file, url, * java resource, etc. * @return The input stream to the resource */ private InputStream getInputStream(String resourceName) throws IOException { // Try class loader to get resource ClassLoader cl = GempakParameterTable.class.getClassLoader(); InputStream s = cl.getResourceAsStream(resourceName); if (s != null) { return s; } // Try the file system File f = new File(resourceName); if (f.exists()) { s = new FileInputStream(f); } if (s != null) { return s; } // Try it as a url Matcher m = Pattern.compile(" ").matcher(resourceName); String encodedUrl = m.replaceAll("%20"); URL dataUrl = new URL(encodedUrl); URLConnection connection = dataUrl.openConnection(); return connection.getInputStream(); }
Example 2
Source File: Re2JRegexp.java From presto with Apache License 2.0 | 5 votes |
public Slice replace(Slice source, Slice replacement) { Matcher matcher = re2jPattern.matcher(source); try { return matcher.replaceAll(replacement); } catch (IndexOutOfBoundsException | IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Illegal replacement sequence: " + replacement.toStringUtf8()); } }
Example 3
Source File: Modification.java From PacketProxy with Apache License 2.0 | 5 votes |
private byte[] replaceRegex(byte[] data, Packet packet) { Pattern pattern = Pattern.compile(this.pattern, Pattern.MULTILINE); Matcher matcher = pattern.matcher(new String(data)); String result = new String(data); while (matcher.find()) { result = matcher.replaceAll(this.replaced); packet.setModified(); } return result.getBytes(); }
Example 4
Source File: Http.java From PacketProxy with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") private String replaceStatusLineToNonProxyStyte(String status_line) throws Exception { String result = status_line; Pattern pattern = Pattern.compile("http://[^/]+"); Matcher matcher = pattern.matcher(status_line); if (matcher.find()) { result = matcher.replaceAll(""); } return result; }
Example 5
Source File: RegexReplaceFilter.java From jinjava with Apache License 2.0 | 5 votes |
@Override public Object filter(Object var, JinjavaInterpreter interpreter, String... args) { if (args.length < 2) { throw new TemplateSyntaxException( interpreter, getName(), "requires 2 arguments (regex string, replacement string)" ); } if (var == null) { return null; } if (var instanceof String) { String s = (String) var; String toReplace = args[0]; String replaceWith = args[1]; try { Pattern p = Pattern.compile(toReplace); Matcher matcher = p.matcher(s); return matcher.replaceAll(replaceWith); } catch (PatternSyntaxException e) { throw new InvalidArgumentException( interpreter, this, InvalidReason.REGEX, 0, toReplace ); } } else { throw new InvalidInputException(interpreter, this, InvalidReason.STRING); } }