本文整理了Java中java.util.regex.Matcher.replaceAll()
方法的一些代码示例,展示了Matcher.replaceAll()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matcher.replaceAll()
方法的具体详情如下:
包路径:java.util.regex.Matcher
类名称:Matcher
方法名:replaceAll
[英]Replaces all occurrences of this matcher's pattern in the input with a given string.
[中]用给定字符串替换输入中此匹配器模式的所有匹配项。
代码示例来源:origin: spring-projects/spring-framework
/**
* 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;
}
}
代码示例来源:origin: apache/incubator-druid
protected static String sanitize(String namespace)
{
Pattern DOT_OR_WHITESPACE = Pattern.compile("[\\s]+|[.]+");
return DOT_OR_WHITESPACE.matcher(namespace).replaceAll("_");
}
}
代码示例来源:origin: Netflix/zuul
private static String cleanCookieHeader(String cookie)
{
for (Pattern stripPtn : RE_STRIP) {
Matcher matcher = stripPtn.matcher(cookie);
if (matcher.find()) {
cookie = matcher.replaceAll("");
}
}
return cookie;
}
代码示例来源:origin: pentaho/pentaho-kettle
@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 "";
}
代码示例来源:origin: pentaho/pentaho-kettle
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 );
}
}
代码示例来源:origin: stackoverflow.com
Pattern regexp = Pattern.compile(".*");
Matcher matcher = regexp.matcher("ABC_012");
matcher.matches();
System.out.println(matcher.group(0));
System.out.println(matcher.replaceAll("$0_suffix"));
代码示例来源:origin: apache/hbase
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);
}
}
代码示例来源:origin: Graylog2/graylog2-server
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);
}
代码示例来源:origin: ankidroid/Anki-Android
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);
}
}
代码示例来源:origin: apache/storm
/**
* 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("_");
}
代码示例来源:origin: stanfordnlp/CoreNLP
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("~");
}
代码示例来源:origin: groovy/groovy-core
boolean doCall(String it) {
return validatePattern.matcher(replacePattern.matcher(it).replaceAll("@")).matches();
}
});
代码示例来源:origin: checkstyle/checkstyle
/**
* 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();
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* 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();
}
}
代码示例来源:origin: code4craft/webmagic
@Override
public String select(String text) {
Matcher matcher = regex.matcher(text);
return matcher.replaceAll(replacement);
}
代码示例来源:origin: apache/kylin
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;
}
代码示例来源:origin: stanfordnlp/CoreNLP
public static String stripSGML(String orig) {
Pattern sgmlPattern = Pattern.compile("<.*?>", Pattern.DOTALL);
Matcher sgmlMatcher = sgmlPattern.matcher(orig);
return sgmlMatcher.replaceAll("");
}
代码示例来源:origin: stanfordnlp/CoreNLP
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;
}
代码示例来源:origin: languagetool-org/languagetool
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;
}
代码示例来源:origin: apache/kafka
private String escape(String jsonStringValue) {
String replace1 = DOUBLEQUOTE.matcher(jsonStringValue).replaceAll(Matcher.quoteReplacement("\\\""));
return BACKSLASH.matcher(replace1).replaceAll(Matcher.quoteReplacement("\\\\"));
}
内容来源于网络,如有侵权,请联系作者删除!