当前位置: 首页>>代码示例>>Java>>正文


Java PatternCompiler.compile方法代码示例

本文整理汇总了Java中org.apache.oro.text.regex.PatternCompiler.compile方法的典型用法代码示例。如果您正苦于以下问题:Java PatternCompiler.compile方法的具体用法?Java PatternCompiler.compile怎么用?Java PatternCompiler.compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.oro.text.regex.PatternCompiler的用法示例。


在下文中一共展示了PatternCompiler.compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: indexOf

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的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;
}
 
开发者ID:anylineorg,项目名称:anyline,代码行数:33,代码来源:RegularUtil.java

示例2: doRereplace

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的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 );
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:25,代码来源:reReplace.java

示例3: realizeTemplate

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的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 );
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:20,代码来源:TextConverter.java

示例4: parseParts

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的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 );
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:28,代码来源:TextConverter.java

示例5: extractPattern

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的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);
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:34,代码来源:TextConverter.java

示例6: Db2ModelReader

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的package包/类
/**
 * Creates a new model reader for Db2 databases.
 * 
 * @param platform The platform that this model reader belongs to
 */
public Db2ModelReader(Platform platform)
{
    super(platform);
    setDefaultCatalogPattern(null);
    setDefaultSchemaPattern(null);

    PatternCompiler compiler = new Perl5Compiler();

	try
	{
		_db2TimePattern      = compiler.compile("'(\\d{2}).(\\d{2}).(\\d{2})'");
		_db2TimestampPattern = compiler.compile("'(\\d{4}\\-\\d{2}\\-\\d{2})\\-(\\d{2}).(\\d{2}).(\\d{2})(\\.\\d{1,8})?'");
    }
	catch (MalformedPatternException ex)
    {
    	throw new DdlUtilsException(ex);
    }
}
 
开发者ID:flex-rental-solutions,项目名称:apache-ddlutils,代码行数:24,代码来源:Db2ModelReader.java

示例7: Oracle8ModelReader

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的package包/类
/**
 * Creates a new model reader for Oracle 8 databases.
 * 
 * @param platform The platform that this model reader belongs to
 */
public Oracle8ModelReader(Platform platform)
{
    super(platform);
    setDefaultCatalogPattern(null);
    setDefaultSchemaPattern(null);
    setDefaultTablePattern("%");

    PatternCompiler compiler = new Perl5Compiler();

	try
	{
		_oracleIsoDatePattern      = compiler.compile("TO_DATE\\('([^']*)'\\, 'YYYY\\-MM\\-DD'\\)");
		_oracleIsoTimePattern      = compiler.compile("TO_DATE\\('([^']*)'\\, 'HH24:MI:SS'\\)");
		_oracleIsoTimestampPattern = compiler.compile("TO_DATE\\('([^']*)'\\, 'YYYY\\-MM\\-DD HH24:MI:SS'\\)");
    }
	catch (MalformedPatternException ex)
    {
    	throw new DdlUtilsException(ex);
    }
}
 
开发者ID:flex-rental-solutions,项目名称:apache-ddlutils,代码行数:26,代码来源:Oracle8ModelReader.java

示例8: Oracle8Builder

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的package包/类
/**
 * Creates a new builder instance.
 * 
 * @param platform The plaftform this builder belongs to
 */
public Oracle8Builder(Platform platform)
{
    super(platform);
    addEscapedCharSequence("'", "''");

    PatternCompiler compiler = new Perl5Compiler();

	try
	{
        _isoDatePattern      = compiler.compile("\\d{4}\\-\\d{2}\\-\\d{2}");
        _isoTimePattern      = compiler.compile("\\d{2}:\\d{2}:\\d{2}");
        _isoTimestampPattern = compiler.compile("\\d{4}\\-\\d{2}\\-\\d{2} \\d{2}:\\d{2}:\\d{2}[\\.\\d{1,8}]?");
    }
	catch (MalformedPatternException ex)
    {
    	throw new DdlUtilsException(ex);
    }
}
 
开发者ID:flex-rental-solutions,项目名称:apache-ddlutils,代码行数:24,代码来源:Oracle8Builder.java

示例9: SybaseModelReader

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的package包/类
/**
 * Creates a new model reader for Sybase databases.
 * 
 * @param platform The platform that this model reader belongs to
 */
public SybaseModelReader(Platform platform)
{
    super(platform);
    setDefaultCatalogPattern(null);
    setDefaultSchemaPattern(null);
    setDefaultTablePattern("%");

    PatternCompiler compiler = new Perl5Compiler();

	try
	{
        _isoDatePattern = compiler.compile("'(\\d{4}\\-\\d{2}\\-\\d{2})'");
        _isoTimePattern = compiler.compile("'(\\d{2}:\\d{2}:\\d{2})'");
    }
	catch (MalformedPatternException ex)
    {
    	throw new DdlUtilsException(ex);
    }
}
 
开发者ID:flex-rental-solutions,项目名称:apache-ddlutils,代码行数:25,代码来源:SybaseModelReader.java

示例10: MSSqlModelReader

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的package包/类
/**
 * Creates a new model reader for Microsoft Sql Server databases.
 * 
 * @param platform The platform that this model reader belongs to
 */
public MSSqlModelReader(Platform platform)
{
    super(platform);
    setDefaultCatalogPattern(null);
    setDefaultSchemaPattern(null);
    setDefaultTablePattern("%");

    PatternCompiler compiler = new Perl5Compiler();

	try
	{
        _isoDatePattern = compiler.compile("'(\\d{4}\\-\\d{2}\\-\\d{2})'");
        _isoTimePattern = compiler.compile("'(\\d{2}:\\d{2}:\\d{2})'");
    }
	catch (MalformedPatternException ex)
    {
    	throw new DdlUtilsException(ex);
    }
}
 
开发者ID:flex-rental-solutions,项目名称:apache-ddlutils,代码行数:25,代码来源:MSSqlModelReader.java

示例11: TimeConverter

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的package包/类
/**
 * Creates a new time converter object.
 */
public TimeConverter()
{
       PatternCompiler compiler = new Perl5Compiler();

       try
       {
           _timePattern = compiler.compile("(?:\\d{4}\\-\\d{2}\\-\\d{2}\\s)?(\\d{2})(?::(\\d{2}))?(?::(\\d{2}))?(?:\\..*)?");
       }
       catch (MalformedPatternException ex)
       {
           throw new DdlUtilsException(ex);
       }

       _calendar = Calendar.getInstance();
	_calendar.setLenient(false);
}
 
开发者ID:flex-rental-solutions,项目名称:apache-ddlutils,代码行数:20,代码来源:TimeConverter.java

示例12: DateConverter

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的package包/类
/**
 * Creates a new date converter object.
 */
public DateConverter()
{
       PatternCompiler compiler = new Perl5Compiler();

       try
       {
           _datePattern = compiler.compile("(\\d{2,4})(?:\\-(\\d{2}))?(?:\\-(\\d{2}))?.*");
       }
       catch (MalformedPatternException ex)
       {
           throw new DdlUtilsException(ex);
       }

       _calendar = Calendar.getInstance();
	_calendar.setLenient(false);
}
 
开发者ID:flex-rental-solutions,项目名称:apache-ddlutils,代码行数:20,代码来源:DateConverter.java

示例13: apply

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的package包/类
public Pattern apply(String pattern) {
    try {
        PatternCompiler pc = new Perl5Compiler();
        return pc.compile(pattern, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK);
    } catch (MalformedPatternException e) {
        throw new ManagerException(e);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:9,代码来源:RegexUtils.java

示例14: apply

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的package包/类
public Pattern apply(String pattern) {
    try {
        PatternCompiler pc = new Perl5Compiler();
        return pc.compile(pattern, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK);
    } catch (MalformedPatternException e) {
        throw new RuntimeException("Regex failed!", e);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:9,代码来源:RegexUtils.java

示例15: apply

import org.apache.oro.text.regex.PatternCompiler; //导入方法依赖的package包/类
public Pattern apply(String input) {
    PatternCompiler pc = new Perl5Compiler();
    try {
        return pc.compile(input,
            Perl5Compiler.CASE_INSENSITIVE_MASK
                    | Perl5Compiler.READ_ONLY_MASK);
    } catch (MalformedPatternException e) {
        throw new ConfigException(e);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:11,代码来源:ConfigHelper.java


注:本文中的org.apache.oro.text.regex.PatternCompiler.compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。