本文整理汇总了Java中org.apache.oro.text.regex.Pattern类的典型用法代码示例。如果您正苦于以下问题:Java Pattern类的具体用法?Java Pattern怎么用?Java Pattern使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pattern类属于org.apache.oro.text.regex包,在下文中一共展示了Pattern类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertStringToPattern
import org.apache.oro.text.regex.Pattern; //导入依赖的package包/类
/**
* 把字符串转成Pattern和UrlType
*
* @param perl5RegExp
* @return
*/
private URLPatternHolder convertStringToPattern(String line) {
URLPatternHolder holder = new URLPatternHolder();
Pattern compiledPattern;
Perl5Compiler compiler = new Perl5Compiler();
String perl5RegExp = line;
try {
compiledPattern = compiler.compile(perl5RegExp, Perl5Compiler.READ_ONLY_MASK);
holder.setCompiledPattern(compiledPattern);
} catch (MalformedPatternException mpe) {
throw new IllegalArgumentException("Malformed regular expression: " + perl5RegExp);
}
if (logger.isDebugEnabled()) {
logger.debug("Added regular expression: " + compiledPattern.getPattern().toString());
}
return holder;
}
示例2: makeOroPattern
import org.apache.oro.text.regex.Pattern; //导入依赖的package包/类
public static Pattern makeOroPattern(String sqlLike) {
Perl5Util perl5Util = new Perl5Util();
try {
sqlLike = perl5Util.substitute("s/([$^.+*?])/\\\\$1/g", sqlLike);
sqlLike = perl5Util.substitute("s/%/.*/g", sqlLike);
sqlLike = perl5Util.substitute("s/_/./g", sqlLike);
} catch (Throwable t) {
String errMsg = "Error in ORO pattern substitution for SQL like clause [" + sqlLike + "]: " + t.toString();
Debug.logError(t, errMsg, module);
throw new IllegalArgumentException(errMsg);
}
try {
return PatternFactory.createOrGetPerl5CompiledPattern(sqlLike, true);
} catch (MalformedPatternException e) {
Debug.logError(e, module);
}
return null;
}
示例3: createOrGetPerl5CompiledPattern
import org.apache.oro.text.regex.Pattern; //导入依赖的package包/类
/**
* Compiles and caches a Perl5 regexp pattern for the given string pattern.
* This would be of no benefits (and may bloat memory usage) if stringPattern is never the same.
* @param stringPattern a Perl5 pattern string
* @param caseSensitive case sensitive true/false
* @return a <code>Pattern</code> instance for the given string pattern
* @throws MalformedPatternException
*/
public static Pattern createOrGetPerl5CompiledPattern(String stringPattern, boolean caseSensitive) throws MalformedPatternException {
Pattern pattern = compiledPerl5Patterns.get(stringPattern);
if (pattern == null) {
Perl5Compiler compiler = new Perl5Compiler();
if (caseSensitive) {
pattern = compiler.compile(stringPattern, Perl5Compiler.READ_ONLY_MASK); // READ_ONLY_MASK guarantees immutability
} else {
pattern = compiler.compile(stringPattern, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK);
}
pattern = compiledPerl5Patterns.putIfAbsentAndGet(stringPattern, pattern);
if (Debug.verboseOn()) {
Debug.logVerbose("Compiled and cached the pattern: '" + stringPattern, module);
}
}
return pattern;
}
示例4: fetch
import org.apache.oro.text.regex.Pattern; //导入依赖的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;
}
示例5: indexOf
import org.apache.oro.text.regex.Pattern; //导入依赖的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;
}
示例6: fetch
import org.apache.oro.text.regex.Pattern; //导入依赖的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;
}
示例7: fetch
import org.apache.oro.text.regex.Pattern; //导入依赖的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;
}
示例8: fetch
import org.apache.oro.text.regex.Pattern; //导入依赖的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;
}
示例9: getTaskPattern
import org.apache.oro.text.regex.Pattern; //导入依赖的package包/类
@Nullable
private Pattern getTaskPattern(String pattern) {
if (!Comparing.strEqual(pattern, myPattern)) {
myCompiledPattern = null;
myPattern = pattern;
}
if (myCompiledPattern == null) {
final String regex = "^.*" + NameUtil.buildRegexp(pattern, 0, true, true);
final Perl5Compiler compiler = new Perl5Compiler();
try {
myCompiledPattern = compiler.compile(regex);
}
catch (MalformedPatternException ignored) {
}
}
return myCompiledPattern;
}
示例10: matchesPatterns
import org.apache.oro.text.regex.Pattern; //导入依赖的package包/类
private boolean matchesPatterns(String url, CollectionProperty patterns)
{
for (JMeterProperty jMeterProperty : patterns)
{
String item = jMeterProperty.getStringValue();
try
{
Pattern pattern = JMeterUtils.getPatternCache().getPattern(item,
Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK);
if (JMeterUtils.getMatcher().matches(url, pattern))
{
return true;
}
}
catch (MalformedCachePatternException e)
{
LOG.warn("Skipped invalid pattern: " + item, e);
}
}
return false;
}
示例11: indexOf
import org.apache.oro.text.regex.Pattern; //导入依赖的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;
}
示例12: listFiles
import org.apache.oro.text.regex.Pattern; //导入依赖的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;
}
示例13: listFilenames
import org.apache.oro.text.regex.Pattern; //导入依赖的package包/类
private static List<String> listFilenames(File dir, String _parentDir, Pattern _pattern, boolean _recurse, int listType) {
File[] files = (_pattern == null ? dir.listFiles() : listFiles(dir, _pattern, listType));
List<String> filesList = new ArrayList<String>();
if (files != null) {
for (int i = 0; i < files.length; i++) {
boolean isDir = files[i].isDirectory();
if (isDir && _recurse) {
filesList.addAll(listFilenames(files[i], _parentDir + files[i].getName() + "/", _pattern, _recurse, listType));
}
if ((listType == LIST_TYPE_DIR && !isDir) || (listType == LIST_TYPE_FILE && isDir))
continue;
if (_pattern == null || listType == LIST_TYPE_ALL ) {
filesList.add(_parentDir + files[i].getName());
}
}
}
return filesList;
}
示例14: doRereplace
import org.apache.oro.text.regex.Pattern; //导入依赖的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.Pattern; //导入依赖的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 );
}