Add class EscapingChars

for BAEL-839
This commit is contained in:
buddhini81 2017-05-22 08:49:36 +05:30 committed by GitHub
parent 468c06ff19
commit 0a5526ea23
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package com.baeldung.regexp;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EscapingChars {
public boolean isMatching(String input, String pattern) {
return input.matches(pattern);
}
public int splitAndCountWords(String input, String pattern) {
return input.split(pattern).length;
}
public int splitAndCountWordsUsingQuoteMethod(String input, String pattern) {
return input.split(Pattern.quote(pattern)).length;
}
public String changeCurrencySymbol(String input, String pattern,
String correctStr) {
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(input);
return m.replaceAll(correctStr);
}
}