本文整理匯總了Java中org.apache.oro.text.regex.Perl5Matcher類的典型用法代碼示例。如果您正苦於以下問題:Java Perl5Matcher類的具體用法?Java Perl5Matcher怎麽用?Java Perl5Matcher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Perl5Matcher類屬於org.apache.oro.text.regex包,在下文中一共展示了Perl5Matcher類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: check
import org.apache.oro.text.regex.Perl5Matcher; //導入依賴的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.Perl5Matcher; //導入依賴的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.Perl5Matcher; //導入依賴的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.Perl5Matcher; //導入依賴的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.Perl5Matcher; //導入依賴的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.Perl5Matcher; //導入依賴的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.Perl5Matcher; //導入依賴的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.Perl5Matcher; //導入依賴的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.Perl5Matcher; //導入依賴的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: indexOf
import org.apache.oro.text.regex.Perl5Matcher; //導入依賴的package包/類
/**
* return index of the first occurence of the pattern in input text
* @param strPattern pattern to search
* @param strInput text to search pattern
* @param offset
* @param caseSensitive
* @return position of the first occurence
* @throws MalformedPatternException
*/
public static int indexOf(String strPattern, String strInput, int offset, boolean caseSensitive) throws MalformedPatternException {
//Perl5Compiler compiler = new Perl5Compiler();
PatternMatcherInput input = new PatternMatcherInput(strInput);
Perl5Matcher matcher = new Perl5Matcher();
int compileOptions=caseSensitive ? 0 : Perl5Compiler.CASE_INSENSITIVE_MASK;
compileOptions+=Perl5Compiler.SINGLELINE_MASK;
if(offset < 1) offset = 1;
Pattern pattern = getPattern(strPattern,compileOptions);
//Pattern pattern = compiler.compile(strPattern,compileOptions);
if(offset <= strInput.length()) input.setCurrentOffset(offset - 1);
if(offset <= strInput.length() && matcher.contains(input, pattern)) {
return matcher.getMatch().beginOffset(0) + 1;
}
return 0;
}
示例11: validateField
import org.apache.oro.text.regex.Perl5Matcher; //導入依賴的package包/類
/**
* Validates an value for a field and returns ErrorData in case of validation error
* @param value
* @return
*/
@Override
public ErrorData validateField(Object value) {
ErrorData errorData = super.validateField(value);
if (errorData!=null) {
return errorData;
}
String textValue = (String)value;
if (textValue==null || textValue.length()==0){
return null;
}
Perl5Matcher pm = new Perl5Matcher();
if (pattern!=null) {
if (!pm.contains(textValue, pattern)) {
LOGGER.warn("The email:'" + textValue +"' is not accepted by the pattern: "+pattern.getPattern());
errorData = new ErrorData("admin.user.profile.err.emailAddress.format");
return errorData;
}
}
return null;
}
示例12: validateRegEx
import org.apache.oro.text.regex.Perl5Matcher; //導入依賴的package包/類
/**
* Helper method to validate the specified string does not contain anything other than
* that specified by the regular expression
* @param aErrors The errors object to populate
* @param aValue the string to check
* @param aRegEx the Perl based regular expression to check the value against
* @param aErrorCode the error code for getting the i8n failure message
* @param aValues the list of values to replace in the i8n messages
* @param aFailureMessage the default error message
*/
public static void validateRegEx(Errors aErrors, String aValue, String aRegEx, String aErrorCode, Object[] aValues, String aFailureMessage) {
if (aValue != null && aRegEx != null && !aRegEx.equals("") && !aValue.trim().equals("")) {
Perl5Compiler ptrnCompiler = new Perl5Compiler();
Perl5Matcher matcher = new Perl5Matcher();
try {
Perl5Pattern aCharPattern = (Perl5Pattern) ptrnCompiler.compile(aRegEx);
if (!matcher.contains(aValue, aCharPattern)) {
aErrors.reject(aErrorCode, aValues, aFailureMessage);
return;
}
}
catch (MalformedPatternException e) {
LogFactory.getLog(ValidatorUtil.class).fatal("Perl pattern malformed: pattern used was "+aRegEx +" : "+ e.getMessage(), e);
}
}
}
示例13: listFiles
import org.apache.oro.text.regex.Perl5Matcher; //導入依賴的package包/類
private static List<File> listFiles(File dir, Pattern _pattern, boolean _recurse, int listType) {
File[] files = (_pattern == null ? dir.listFiles() : listFiles(dir, _pattern, listType));
List<File> filesList = new ArrayList<File>();
Perl5Matcher matcher = ( _pattern == null ? null : new Perl5Matcher() );
if (files != null) {
for (int i = 0; i < files.length; i++) {
boolean isDir = files[i].isDirectory();
if (isDir && _recurse) {
filesList.addAll(listFiles(files[i], _pattern, _recurse, listType));
}
if ((listType == LIST_TYPE_DIR && !isDir) || (listType == LIST_TYPE_FILE && isDir))
continue;
if ( _pattern == null || matcher.matches( files[i].getName(), _pattern ) ){
filesList.add(files[i]);
}
}
}
return filesList;
}
示例14: doRereplace
import org.apache.oro.text.regex.Perl5Matcher; //導入依賴的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 );
}
示例15: realizeTemplate
import org.apache.oro.text.regex.Perl5Matcher; //導入依賴的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 );
}