本文整理汇总了Java中org.apache.oro.text.regex.PatternMatcher类的典型用法代码示例。如果您正苦于以下问题:Java PatternMatcher类的具体用法?Java PatternMatcher怎么用?Java PatternMatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PatternMatcher类属于org.apache.oro.text.regex包,在下文中一共展示了PatternMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
public boolean check(String action, String method) {
if (!StringUtil.isBlank(action)) {
PatternMatcher matcher = new Perl5Matcher();
Iterator<ActionPatternHolder> iter = actionPatternList.iterator();
while (iter.hasNext()) {
ActionPatternHolder holder = (ActionPatternHolder) iter.next();
if (StringUtils.isNotEmpty(action) && matcher.matches(action, holder.getActionPattern())
&& StringUtils.isNotEmpty(method) && matcher.matches(method, holder.getMethodPattern())) {
if (logger.isDebugEnabled()) {
logger.debug("Candidate is: '" + action + "|" + method + "'; pattern is "
+ holder.getActionName() + "|" + holder.getMethodName() + "; matched=true");
}
return true;
}
}
}
return false;
}
示例2: findFirst
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
public static String findFirst(String originalStr, String regex) {
if (StringUtils.isBlank(originalStr) || StringUtils.isBlank(regex)) {
return StringUtils.EMPTY;
}
PatternMatcher matcher = new Perl5Matcher();
if (matcher.contains(originalStr, patterns.get(regex))) {
return StringUtils.trimToEmpty(matcher.getMatch().group(0));
}
return StringUtils.EMPTY;
}
示例3: check
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
public boolean check(String requestUrl) {
if (StringUtils.isBlank(requestUrl)) {
return false;
}
if (logger.isDebugEnabled()) {
logger.debug("Converted URL to lowercase, from: '" + requestUrl + "'; to: '" + requestUrl + "'");
}
PatternMatcher matcher = new Perl5Matcher();
Iterator<URLPatternHolder> iter = urlProtectedList.iterator();
while (iter.hasNext()) {
URLPatternHolder holder = (URLPatternHolder) iter.next();
if (matcher.matches(requestUrl, holder.getCompiledPattern())) {
if (logger.isDebugEnabled()) {
logger.debug("Candidate is: '" + requestUrl + "'; pattern is "
+ holder.getCompiledPattern().getPattern() + "; matched=true");
}
return true;
}
}
return false;
}
示例4: exec
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
@Override
public void exec(Map<String, Object> inMap, Map<String, Object> results, List<Object> messages, Locale locale, ClassLoader loader) {
Object obj = inMap.get(fieldName);
String fieldValue = null;
try {
fieldValue = (String) ObjectType.simpleTypeConvert(obj, "String", null, locale);
} catch (GeneralException e) {
messages.add("Could not convert field value for comparison: " + e.getMessage());
return;
}
if (pattern == null) {
messages.add("Could not compile regular expression \"" + expr + "\" for validation");
return;
}
PatternMatcher matcher = new Perl5Matcher();
if (!matcher.matches(fieldValue, pattern)) {
addMessage(messages, loader, locale);
}
}
示例5: fetch
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
* 提取子串
* @param src 输入字符串
* @param regx 表达式
* @return
*/
public List<List<String>> fetch(String src, String regx){
List<List<String>> list = new ArrayList<List<String>>();
try{
Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
PatternMatcher matcher = new Perl5Matcher();
PatternMatcherInput input = new PatternMatcherInput(src);
while(matcher.matches(input, pattern)){
MatchResult matchResult = matcher.getMatch();
int groups = matchResult.groups();
List<String> item = new ArrayList<String>();
for(int i=0; i<=groups; i++){
item.add(matchResult.group(i));
}
list.add(item);
}
}catch(Exception e){
if(ConfigTable.isDebug()){
e.printStackTrace();
}
}
return list;
}
示例6: indexOf
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
* 字符串下标 regx在src中首次出现的位置
* @param src
* @param regx
* @param idx 有效开始位置
* @return
* @throws Exception
*/
public static int indexOf(String src, String regx, int begin){
int idx = -1;
try{
PatternCompiler patternCompiler = new Perl5Compiler();
Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
PatternMatcher matcher = new Perl5Matcher();
PatternMatcherInput input = new PatternMatcherInput(src);
while(matcher.contains(input, pattern)){
MatchResult matchResult = matcher.getMatch();
int tmp = matchResult.beginOffset(0);
if(tmp >= begin){//匹配位置从begin开始
idx = tmp;
break;
}
}
}catch(Exception e){
log.error("fetch(String,String):\n"+"src="+src+"\regx="+regx+"\n"+e);
if(ConfigTable.isDebug()){
e.printStackTrace();
}
}
return idx;
}
示例7: fetch
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
* 提取子串
* @param src 输入字符串
* @param regx 表达式
* @return
*/
public List<List<String>> fetch(String src, String regx){
List<List<String>> list = new ArrayList<List<String>>();
try{
Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
PatternMatcher matcher = new Perl5Matcher();
PatternMatcherInput input = new PatternMatcherInput(src);
while(matcher.matchesPrefix(input, pattern)){
MatchResult matchResult = matcher.getMatch();
int groups = matchResult.groups();
List<String> item = new ArrayList<String>();
for(int i=0; i<=groups; i++){
item.add(matchResult.group(i));
}
list.add(item);
}
}catch(Exception e){
if(ConfigTable.isDebug()){
e.printStackTrace();
}
}
return list;
}
示例8: fetch
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
* 提取子串
* @param src 输入字符串
* @param regx 表达式
* @return
*/
public List<List<String>> fetch(String src, String regx){
List<List<String>> list = new ArrayList<List<String>>();
try{
Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
PatternMatcher matcher = new Perl5Matcher();
PatternMatcherInput input = new PatternMatcherInput(src);
while(matcher.contains(input, pattern)){
MatchResult matchResult = matcher.getMatch();
int groups = matchResult.groups();
List<String> item = new ArrayList<String>();
for(int i=0; i<groups; i++){
item.add(matchResult.group(i));
}
list.add(item);
}
}catch(Exception e){
log.error("fetch(String,String):\n"+"src="+src+"\regx="+regx+"\n"+e);
if(ConfigTable.isDebug()){
e.printStackTrace();
}
}
return list;
}
示例9: fetch
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
* 提取子串
* @param src 输入字符串
* @param regx 表达式
* @return
*/
public List<List<String>> fetch(String src, String regx){
List<List<String>> list = new ArrayList<List<String>>();
try{
Pattern pattern = patternCompiler.compile(regx, Perl5Compiler.CASE_INSENSITIVE_MASK);
PatternMatcher matcher = new Perl5Matcher();
PatternMatcherInput input = new PatternMatcherInput(src);
while(matcher.contains(input, pattern)){
MatchResult matchResult = matcher.getMatch();
int groups = matchResult.groups();
List<String> item = new ArrayList<String>();
for(int i=0; i<groups; i++){
item.add(matchResult.group(i));
}
list.add(item);
}
}catch(Exception e){
log.error("fetch(String,String):\n"+"src="+src+"\regx="+regx+"\n"+e);
}
return list;
}
示例10: doRereplace
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
protected String doRereplace( String _theString, String _theRE, String _theSubstr, boolean _casesensitive, boolean _replaceAll ) throws cfmRunTimeException{
int replaceCount = _replaceAll ? Util.SUBSTITUTE_ALL : 1;
PatternMatcher matcher = new Perl5Matcher();
Pattern pattern = null;
PatternCompiler compiler = new Perl5Compiler();
try {
if ( _casesensitive ){
pattern = compiler.compile( _theRE, Perl5Compiler.SINGLELINE_MASK );
}else{
pattern = compiler.compile( _theRE, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK );
}
} catch(MalformedPatternException e){ // definitely should happen since regexp is hardcoded
cfCatchData catchD = new cfCatchData();
catchD.setType( "Function" );
catchD.setMessage( "Internal Error" );
catchD.setDetail( "Invalid regular expression ( " + _theRE + " )" );
throw new cfmRunTimeException( catchD );
}
// Perform substitution and print result.
return Util.substitute(matcher, pattern, new Perl5Substitution( processSubstr( _theSubstr ) ), _theString, replaceCount );
}
示例11: realizeTemplate
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
* Convert a template query by replacing the template areas with
* the given replacement string, which is generally a column name.
*/
private static String realizeTemplate( String template, String replacement ) {
String output = "";
PatternCompiler compiler = new Perl5Compiler();
PatternMatcher matcher = new Perl5Matcher();
try {
Pattern pattern = compiler.compile( kTemplateVariable );
output = Util.substitute( matcher, pattern, new StringSubstitution(replacement), template, Util.SUBSTITUTE_ALL );
}
catch( MalformedPatternException mpe ) {
System.err.println( "TextConverter.realizeTemplate(): " + mpe );
}
return( output );
}
示例12: parseParts
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
* @return Collection of strings extracted from input 'term', respecting quoted regions.
* Thus input = "foo 'bar baz' zip" will return "foo", "bar baz", "zip".
*/
private static Collection<String> parseParts( String term )
{
// first, get all the quoted strings.
Collection<String> searchParts = new ArrayList<String>();
String reducedTerm = extractPattern( "'([^']*)'", term, searchParts );
reducedTerm = extractPattern( "\"([^\"]*)\"", reducedTerm, searchParts );
// second, get all remaining non-empty terms.
if( false == reducedTerm.trim().equals( "" ) )
{
PatternCompiler compiler = new Perl5Compiler();
PatternMatcher matcher = new Perl5Matcher();
try {
Pattern pattern = compiler.compile( "\\s+" );
Util.split( searchParts, matcher, pattern, reducedTerm );
}
catch( MalformedPatternException mpe ) {
System.err.println( "TextConverter.parseParts(): " + mpe );
}
}
return( searchParts );
}
示例13: extractPattern
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
* Given a regular expression, remove matches from the input string and
* store them in the given Collection. Note: it is assumed that the
* regular expression has one parenthasized matching group which
* is the text to be placed in the Collection. Text outside of that
* group which still matches the regexp is deleted.
* @return String that is 'input' with all 'regex' matches deleted.
*/
private static String extractPattern(String regex, String input, Collection<String> found) {
String output = "";
PatternCompiler compiler = new Perl5Compiler();
PatternMatcher matcher = new Perl5Matcher();
try {
Pattern pattern = compiler.compile(regex);
PatternMatcherInput matcherInput = new PatternMatcherInput( input );
while( matcher.contains( matcherInput, pattern ) ) {
MatchResult result = matcher.getMatch();
if( result.groups() > 0 ) {
String sub = result.group( 1 );
found.add( sub );
}
}
output = Util.substitute( matcher, pattern, new StringSubstitution(), input, Util.SUBSTITUTE_ALL );
}
catch( MalformedPatternException mpe ) {
System.err.println( "TextConverter.extractPattern(): " + mpe );
}
return (output);
}
示例14: parseMode
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
/**
* 解析DataMedia中的namespace和name,支持offer[1-128]分库的定义
*/
public static ModeValue parseMode(String value) {
PatternMatcher matcher = new Perl5Matcher();
if (matcher.matches(value, patterns.get(MODE_PATTERN))) {
MatchResult matchResult = matcher.getMatch();
String prefix = matchResult.group(1);
String startStr = matchResult.group(3);
String ednStr = matchResult.group(4);
int start = Integer.valueOf(startStr);
int end = Integer.valueOf(ednStr);
String postfix = matchResult.group(5);
List<String> values = new ArrayList<String>();
for (int i = start; i <= end; i++) {
StringBuilder builder = new StringBuilder(value.length());
String str = String.valueOf(i);
// 处理0001类型
if (startStr.length() == ednStr.length() && startStr.startsWith("0")) {
str = StringUtils.leftPad(String.valueOf(i), startStr.length(), '0');
}
builder.append(prefix).append(str).append(postfix);
values.add(builder.toString());
}
return new ModeValue(Mode.MULTI, values);
} else if (isWildCard(value)) {// 通配符支持
return new ModeValue(Mode.WILDCARD, Arrays.asList(value));
} else {
return new ModeValue(Mode.SINGLE, Arrays.asList(value));
}
}
示例15: testWildCard
import org.apache.oro.text.regex.PatternMatcher; //导入依赖的package包/类
@Test
public void testWildCard() {
PatternMatcher matcher = new Perl5Matcher();
Pattern pattern = null;
PatternCompiler pc = new Perl5Compiler();
try {
pattern = pc.compile("havana_us_.*", Perl5Compiler.DEFAULT_MASK);
} catch (MalformedPatternException e) {
throw new ConfigException(e);
}
boolean ismatch = matcher.matches("havana_us_0001", pattern);
System.out.println(ismatch);
}