當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。