/** * Returns the length of the given pattern, where template variables are considered to be 1 long. */ public int getLength() { if (this.length == null) { this.length = (this.pattern != null ? VARIABLE_PATTERN.matcher(this.pattern).replaceAll("#").length() : 0); } return this.length; } }
protected static String sanitize(String namespace) { Pattern DOT_OR_WHITESPACE = Pattern.compile("[\\s]+|[.]+"); return DOT_OR_WHITESPACE.matcher(namespace).replaceAll("_"); } }
private static String cleanCookieHeader(String cookie) { for (Pattern stripPtn : RE_STRIP) { Matcher matcher = stripPtn.matcher(cookie); if (matcher.find()) { cookie = matcher.replaceAll(""); } } return cookie; }
@VisibleForTesting String substitute( String input, String regex, String substitution ) { Pattern replace = Pattern.compile( regex ); Matcher matcher = replace.matcher( input ); if ( matcher.find() ) { return matcher.replaceAll( substitution ); } return ""; }
public static String replaceString( String originalString, Pattern pattern, String replaceByString ) { if ( originalString == null ) { return null; } final Matcher matcher = pattern.matcher( originalString ); if ( replaceByString == null ) { if ( matcher.matches() ) { return null; } else { return originalString; } } else { return matcher.replaceAll( replaceByString ); } }
private static void process(String urlstring) { try { URL url = new URL(urlstring); System.out.println("Connecting to " + url); URLConnection connection = url.openConnection(); connection.connect(); try (InputStreamReader streamReader = new InputStreamReader(connection.getInputStream()); BufferedReader bufferedReader = new BufferedReader(streamReader)) { for(String line; (line = bufferedReader.readLine()) != null; ) { if (line.startsWith(MARKER)) { System.out.println(TAG.matcher(line).replaceAll("")); } } } } catch (IOException ioe) { System.err.println("" + ioe); } }
public Result runExtractor(String value) { final Matcher matcher = pattern.matcher(value); final boolean found = matcher.find(); if (!found) { return null; } final int start = matcher.groupCount() > 0 ? matcher.start(1) : -1; final int end = matcher.groupCount() > 0 ? matcher.end(1) : -1; final String s; try { s = replaceAll ? matcher.replaceAll(replacement) : matcher.replaceFirst(replacement); } catch (Exception e) { throw new RuntimeException("Error while trying to replace string", e); } return new Result(s, start, end); }
private static String noSound(Matcher match, String repl) { if (match.group(2).startsWith("sound:")) { // return without modification return match.group(0); } else { return r.matcher(match.group(0)).replaceAll(repl); } }
/** * sanitizeStreamName. * @param streamName streamName * @return sanitizeStreamName */ public static String sanitizeStreamName(String streamName) { Pattern pattern = Pattern.compile("(?![A-Za-z_\\-:\\.])."); Pattern pattern2 = Pattern.compile("^[A-Za-z]"); Matcher matcher = pattern2.matcher(streamName); Matcher matcher2 = pattern.matcher("\\s" + streamName); if (matcher.find()) { matcher2 = pattern.matcher(streamName); } return matcher2.replaceAll("_"); }
private static String greekify(String str) { // don't take out leading or ending ones, just internal // and remember padded with < > characters String pattern = "(alpha)|(beta)|(gamma)|(delta)|(epsilon)|(zeta)|(kappa)|(lambda)|(rho)|(sigma)|(tau)|(upsilon)|(omega)"; Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(str); return m.replaceAll("~"); }
boolean doCall(String it) { return validatePattern.matcher(replacePattern.matcher(it).replaceAll("@")).matches(); } });
/** * Checks if literal has Unicode chars. * @param literal String literal. * @return true if literal has Unicode chars. */ private static boolean hasUnicodeChar(String literal) { final String literalWithoutEscapedBackslashes = ESCAPED_BACKSLASH.matcher(literal).replaceAll(""); return UNICODE_REGEXP.matcher(literalWithoutEscapedBackslashes).find(); }
/** * Configures the client to send HTTP/HTTPS request to the URL. * Supports SPENGO for authentication. * @param urlString URL and query string to the daemon's web UI * @throws Exception if unable to connect */ private void process(String urlString) throws Exception { URL url = new URL(urlString); System.out.println("Connecting to " + url); URLConnection connection = connect(url); // read from the servlet BufferedReader in = new BufferedReader( new InputStreamReader(connection.getInputStream(), Charsets.UTF_8)); for (String line;;) { line = in.readLine(); if (line == null) { break; } if (line.startsWith(MARKER)) { System.out.println(TAG.matcher(line).replaceAll("")); } } in.close(); } }
@Override public String select(String text) { Matcher matcher = regex.matcher(text); return matcher.replaceAll(replacement); }
static String quoteIdentifier(String sqlExpr, String quotation, String identifier, List<String> identifierPatterns) { String quotedIdentifier = quotation + identifier.trim() + quotation; for (String pattern : identifierPatterns) { Matcher matcher = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(sqlExpr); if (matcher.find()) { sqlExpr = matcher.replaceAll("$1" + quotedIdentifier + "$3"); } } return sqlExpr; }
public static String stripSGML(String orig) { Pattern sgmlPattern = Pattern.compile("<.*?>", Pattern.DOTALL); Matcher sgmlMatcher = sgmlPattern.matcher(orig); return sgmlMatcher.replaceAll(""); }
private String createNormalizedForm(String word) { if (normalize) { word = StringUtils.normalize(word); } if (caseInsensitive) { word = word.toLowerCase(); } if (ignorePunctuation) { word = punctWhitespacePattern.matcher(word).replaceAll(""); } else if (ignorePunctuationTokens) { if (punctWhitespacePattern.matcher(word).matches()) { word = ""; } } word = whitespacePattern.matcher(word).replaceAll(""); return word; }
private Map<Integer, String> replaceSoftHyphens(List<String> tokens) { Pattern ignoredCharacterRegex = language.getIgnoredCharactersRegex(); Map<Integer, String> ignoredCharsTokens = new HashMap<>(); if (ignoredCharacterRegex == null) { return ignoredCharsTokens; } for (int i = 0; i < tokens.size(); i++) { if (ignoredCharacterRegex.matcher(tokens.get(i)).find()) { ignoredCharsTokens.put(i, tokens.get(i)); tokens.set(i, ignoredCharacterRegex.matcher(tokens.get(i)).replaceAll("")); } } return ignoredCharsTokens; }
private String escape(String jsonStringValue) { String replace1 = DOUBLEQUOTE.matcher(jsonStringValue).replaceAll(Matcher.quoteReplacement("\\\"")); return BACKSLASH.matcher(replace1).replaceAll(Matcher.quoteReplacement("\\\\")); }