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


Java Matcher.replaceFirst方法代码示例

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


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

示例1: getTokens

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * Gets all tokens.
 * @return An array of tokens.
 * @throws IllegalStateException If an unknown entry was found.
 */
Token[] getTokens()
        throws IllegalStateException {
    if(cached != null) {
        return cached;
    }
    LinkedList<Token> tokens = new LinkedList<>();
    whileLoop:
    while(!input.isEmpty()) {
        input = input.trim();
        for(Type type : Type.values()) {
            Matcher matcher = type.pattern.matcher(input);
            if(!matcher.find()) {
                continue;
            }
            String tokenString = matcher.group().trim();
            tokens.add(new Token(tokenString, type));
            input = matcher.replaceFirst("");
            continue whileLoop;
        }
        throw new IllegalStateException("Unknown token \"" + input.replace("\"", "\\\"") + "\"");
    }
    cached = tokens.toArray(new Token[tokens.size()]);
    return cached;
}
 
开发者ID:Arraying,项目名称:Kotys,代码行数:30,代码来源:JSONTokenizer.java

示例2: toStringVerbose

import java.util.regex.Matcher; //导入方法依赖的package包/类
public String toStringVerbose() {
    String stringRepresentation = getData().toString() + ":[";

    for (GenericTreeNode<T> node : getChildren()) {
        stringRepresentation += node.getData().toString() + ", ";
    }

    //Pattern.DOTALL causes ^ and $ to match. Otherwise it won't. It's retarded.
    Pattern pattern = Pattern.compile(", $", Pattern.DOTALL);
    Matcher matcher = pattern.matcher(stringRepresentation);

    stringRepresentation = matcher.replaceFirst("");
    stringRepresentation += "]";

    return stringRepresentation;
}
 
开发者ID:KeepTheBeats,项目名称:alevin-svn2,代码行数:17,代码来源:GenericTreeNode.java

示例3: format

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * 格式化字符串中的零
 *
 * @param obj
 * @return
 */
public static String format(String obj) {
	if (!obj.startsWith("0")) {
		return obj;
	}
	Pattern p = Pattern.compile("^0*");
	Matcher m = p.matcher(obj);
	String result = null;
	if (m.find()) {
		result = obj.substring(m.start() + 1);
		m.replaceFirst("");
	}
	if (result.startsWith("0")) {
		return format(result);
	}
	return result;
}
 
开发者ID:subaochen,项目名称:java-tutorial,代码行数:23,代码来源:MoneyTransform.java

示例4: unnumbered

import java.util.regex.Matcher; //导入方法依赖的package包/类
private String[] unnumbered(String actual[])
{
    for (int i = actual.length-1; i >= 0; i--)
    {
        StringJoiner sj = new StringJoiner("\n");
        String[] bits = actual[i].split("\n");
        for (String bit: bits)
        {
            Pattern p = Pattern.compile("^[0-9.]*");
            Matcher m = p.matcher(bit);
            bit = m.replaceFirst("0");
            sj.add(bit);
        }
        actual[i] = sj.toString();
    }
    return actual;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:18,代码来源:TransformerDebugTest.java

示例5: replaceOneString

import java.util.regex.Matcher; //导入方法依赖的package包/类
@Override
public String replaceOneString(String body, Request request) {
    Matcher parameterMatcher = PARAMETER.matcher(body);
    parameterMatcher.find();
    String match = parameterMatcher.group();
    String parameter = "";
    Map<String, String> query = getQueryFromUri(match);
    try {
        if (query.containsKey(INDEX_PARAMETER)) {
            int index = Integer.parseInt(query.get(INDEX_PARAMETER));
            if (index < request.url().querySize()) {
                parameter = request.url().queryParameterValue(index);
            }
        } else if (query.containsKey(NAME_PARAMETER)) {
            String name = query.get(NAME_PARAMETER);
            if (request.url().queryParameterNames().contains(name)) {
                parameter = request.url().queryParameterValues(name).get(0);
            }
        }
        body = parameterMatcher.replaceFirst(parameter);
    } catch (Exception e) {
        Timber.e(e, "You did something wrong when setting up your parameter interceptor. ");
    }
    return body;
}
 
开发者ID:politedog,项目名称:mock-interceptor,代码行数:26,代码来源:AbstractMockedApiInterceptor.java

示例6: handleAnySqlPostTranslation

import java.util.regex.Matcher; //导入方法依赖的package包/类
@Override
public String handleAnySqlPostTranslation(String string, Change change) {
    if (change != null && change.getMetadataSection() != null
            && change.getMetadataSection().isTogglePresent(TextMarkupDocumentReader.TOGGLE_DISABLE_QUOTED_IDENTIFIERS)) {
        if (!change.getChangeType().getName().equals(ChangeType.VIEW_STR)) {
            // only needed for HSQL seemingly for views only, seemingly not for H2
            string = string.replace('"', '\'');
        }
    }

    Matcher varbinaryDefaultMatcher = this.varbinaryDefaultPattern.matcher(string);
    if (varbinaryDefaultMatcher.find()) {
        string = varbinaryDefaultMatcher.replaceFirst("varbinary(1)" + varbinaryDefaultMatcher.group(1));
    }

    return string;
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:18,代码来源:MsSqlToHsqlSqlTranslator.java

示例7: getUrl

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * If the URL contains a special variable width indicator (eg "__w-200-400-800__")
 * we get the buckets from the URL (200, 400 and 800 in the example) and replace
 * the URL with the best bucket for the requested width (the bucket immediately
 * larger than the requested width).
 */
@Override
protected String getUrl(String model, int width, int height, Options options) {
    Matcher m = PATTERN.matcher(model);
    int bestBucket = 0;
    if (m.find()) {
        String[] found = m.group(1).split("-");
        for (String bucketStr : found) {
            bestBucket = Integer.parseInt(bucketStr);
            if (bestBucket >= width) {
                // the best bucket is the first immediately bigger than the requested width
                break;
            }
        }
        if (bestBucket > 0) {
            model = m.replaceFirst("w" + bestBucket);
        }
    }
    return model;
}
 
开发者ID:alphater,项目名称:garras,代码行数:26,代码来源:PixelsModelLoader.java

示例8: onCreateObjectUrl

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * Creates a full url from the class annotation url and object attributes.
 */
protected String onCreateObjectUrl(String url, NetworkTask.HttpMethod method)
{
    String result = url;
    while (true) {
        Matcher regexMatcher = ATTRIBUTE_REGEXP.matcher(result);
        if (regexMatcher.find()) {
            String attributeName = regexMatcher.group();
            Object value = ReflectionHelper.getAttribute(this, null, attributeName.substring(1, attributeName.length() - 1));
            result = regexMatcher.replaceFirst(value.toString());
        }
        else {
            break;
        }
    }
    return result;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-android,代码行数:20,代码来源:RemoteObject.java

示例9: replaceSubstitution

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * Replace the matches of the from pattern in the base string with the value
 * of the to string.
 * @param base the string to transform
 * @param from the pattern to look for in the base string
 * @param to the string to replace matches of the pattern with
 * @param repeat whether the substitution should be repeated
 * @return
 */
static String replaceSubstitution(String base, Pattern from, String to, 
                                  boolean repeat) {
  Matcher match = from.matcher(base);
  if (repeat) {
    return match.replaceAll(to);
  } else {
    return match.replaceFirst(to);
  }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:19,代码来源:KerberosName.java

示例10: setFont

import java.util.regex.Matcher; //导入方法依赖的package包/类
public static String setFont(String style, String font) {
    Matcher ans = fontFamily.matcher(style);
    if (ans.find()) {
        return ans.replaceFirst("-fx-font-family: \"" + font + "\";");
    } else {
        return (style + "-fx-font-family: \"" + font + "\";");
    }
}
 
开发者ID:Glavo,项目名称:ClassViewer,代码行数:9,代码来源:FontUtils.java

示例11: isBlockFileInPrevious

import java.util.regex.Matcher; //导入方法依赖的package包/类
private boolean isBlockFileInPrevious(File blockFile) {
  Pattern blockFilePattern = Pattern.compile(String.format(
    "^(.*%1$scurrent%1$s.*%1$s)(current)(%1$s.*)$",
    Pattern.quote(File.separator)));
  Matcher matcher = blockFilePattern.matcher(blockFile.toString());
  String previousFileName = matcher.replaceFirst("$1" + "previous" + "$3");
  return ((new File(previousFileName)).exists());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:9,代码来源:TestDataNodeRollingUpgrade.java

示例12: handleAnySqlPostTranslation

import java.util.regex.Matcher; //导入方法依赖的package包/类
@Override
public String handleAnySqlPostTranslation(String string, Change change) {
    string = string.replaceAll("(?i)getdate\\(\\)", "CURRENT_DATE");

    // keeping for backwards-compatibility
    string = string.replaceAll("(?i)dbo\\.", "");

    // only for Sybase ASE - the "modify" keyword should change to "alter column"
    Matcher modifyMatcher = RegexpPatterns.modifyTablePattern.matcher(string);
    if (modifyMatcher.find()) {
        string = modifyMatcher.replaceFirst("ALTER TABLE " + modifyMatcher.group(1) + " ALTER COLUMN");
    }

    return string;
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:16,代码来源:MsSqlToInMemorySqlTranslator.java

示例13: getLocationInformation

import java.util.regex.Matcher; //导入方法依赖的package包/类
@Override
public LocationInfo getLocationInformation() {
    if (this.locationInfo == null) {
        // HACK: Use preprocessor information
        String msg = this.event.getMessage().toString();
        Matcher m = PREPROCESSOR_PATTERN.matcher(msg);
        if (LOG.isDebugEnabled()) LOG.debug("Checking whether we can use PREPROCESSOR info for location: " + msg);
        
        if (m.find()) {
            if (LOG.isDebugEnabled()) LOG.debug("Using preprocessor information get source location [" + m + "]");
            
            String fileName = m.group(1);
            int lineNumber = Integer.parseInt(m.group(2));
            this.locationInfo = new FastLocationInfo(lineNumber, fileName, "", "");
            this.cleanMessage = m.replaceFirst("");
        } else {
            if (LOG.isDebugEnabled()) LOG.debug("Using stack offset lookup to get source location");
            StackTraceElement stack[] = Thread.currentThread().getStackTrace();
//            System.err.println(String.format("Stack=%d / Offset=%d", stack.length, this.stackOffset));
            if (this.stackOffset < stack.length) {
//                for (int i = 0; i < stack.length; i++) {
//                    System.err.printf("[%02d] %s\n", i, stack[i]);
//                }
                this.locationInfo = new FastLocationInfo(stack[this.stackOffset].getLineNumber(),
                                                         stack[this.stackOffset].getFileName(),
                                                         stack[this.stackOffset].getClassName(),
                                                         stack[this.stackOffset].getMethodName());
            }
        }
    }
    return (this.locationInfo);
}
 
开发者ID:s-store,项目名称:s-store,代码行数:33,代码来源:FastLoggingEvent.java

示例14: replaceXmlHeaderVersion

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * Replace header with xml version 1.0 to version 1.1.
 * @param xmlEntry string for replacing
 * @return new string after replacing
 */
@NotNull static String replaceXmlHeaderVersion(@NotNull final String xmlEntry){
  final Matcher matcher = XML_HEADER_PATTERN.matcher(xmlEntry);
  if (matcher.find()) {
    return matcher.replaceFirst(matcher.group(1) + "1.1" + matcher.group(3));
  }
  return xmlEntry;
}
 
开发者ID:unix-junkie,项目名称:teamcity-autotools-plugin,代码行数:13,代码来源:DejagnuTestsXMLParser.java

示例15: handleAnySqlPostTranslation

import java.util.regex.Matcher; //导入方法依赖的package包/类
@Override
public String handleAnySqlPostTranslation(String string, Change change) {

    // FKs cannot have names in hsql or h2
    Matcher fkWithNameMatcher = RegexpPatterns.fkWithNamePattern.matcher(string);
    if (fkWithNameMatcher.find()) {
        string = fkWithNameMatcher.replaceFirst("FOREIGN KEY (");
    }

    return string;
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:12,代码来源:ForeignKeyNameRemovalSqlTranslator.java


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