當前位置: 首頁>>代碼示例>>Java>>正文


Java Matcher.groupCount方法代碼示例

本文整理匯總了Java中java.util.regex.Matcher.groupCount方法的典型用法代碼示例。如果您正苦於以下問題:Java Matcher.groupCount方法的具體用法?Java Matcher.groupCount怎麽用?Java Matcher.groupCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.regex.Matcher的用法示例。


在下文中一共展示了Matcher.groupCount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: genWinArgs

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Does a poor-man's parse of a MSDOS command line and parses it
 * into a WIndows cmd.exe invocation to approximate.
 */
static private String[] genWinArgs(String monolithic) {
    List list = new ArrayList();
    list.add("cmd.exe");
    list.add("/y");
    list.add("/c");
    Matcher m = wincmdPattern.matcher(monolithic);
    String[] internalTokens;
    while (m.find()) {
        for (int i = 1; i <= m.groupCount(); i++) {
            if (m.group(i) == null) continue;
            if (m.group(i).length() > 1 && m.group(i).charAt(0) == '"') {
                list.add(m.group(i).substring(1, m.group(i).length() - 1));
                continue;
            }
            internalTokens = m.group(i).split("\\s+");
            for (int j = 0; j < internalTokens.length; j++)
                list.add(internalTokens[j]);
        }
    }
    return (String[]) list.toArray(new String[] {});
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:26,代碼來源:SqlFile.java

示例2: ofMatcher

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static XmEntityKey ofMatcher(String xmKey, Pattern pattern) {
    Objects.requireNonNull(xmKey, "XM entity key can't be null");

    Matcher xmKeyMatcher = pattern.matcher(xmKey);
    if (!xmKeyMatcher.matches()) {
        // add more appropriate exception ...
        throw new BusinessException("XM entity key '" + xmKey + "' doesn't match pattern: "
                                               + pattern.pattern());
    }

    int count = xmKeyMatcher.groupCount();
    String groups[] = new String[count];
    for (int i = 0; i < count; i++) {
        groups[i] = xmKeyMatcher.group(i + 1);
    }
    return new XmEntityKey(xmKey, groups);
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:18,代碼來源:XmEntityKey.java

示例3: handleUserstate

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Parses the received line and saves data such as the users color, if the user is mod, subscriber or turbouser
 * @param line
 */
private void handleUserstate(String line) {
	Matcher userstateMatcher = userStatePattern.matcher(line);
	if(userstateMatcher.find()) {
		userColor = userstateMatcher.group(1);
		userDisplayName = userstateMatcher.group(2);
		String emoteSets = userstateMatcher.group(3);
		userIsMod = userstateMatcher.group(4).equals("1");
		userIsSubscriber = userstateMatcher.group(5).equals("1");
		if (userstateMatcher.groupCount() > 7) {
			userIsTurbo = userstateMatcher.group(7).equals("1");
		}

	} else {
		Log.e(LOG_TAG, "Failed to find userstate pattern in: \n" + line);
	}
}
 
開發者ID:SebastianRask,項目名稱:Pocket-Plays-for-Twitch,代碼行數:21,代碼來源:ChatManager.java

示例4: extract

import java.util.regex.Matcher; //導入方法依賴的package包/類
private static String extract(String response, Pattern p) {
    Matcher matcher = p.matcher(response);
    if (matcher.find() && matcher.groupCount() >= 1) {
        return OAuthEncoder.decode(matcher.group(1));
    } else {
        throw new OAuthException("Response body is incorrect. Can't extract token and secret from this: " + response);
    }
}
 
開發者ID:fivef,項目名稱:add_to_evernote_note,代碼行數:9,代碼來源:EvernoteOAuthHelper.java

示例5: getCorrectGroup

import java.util.regex.Matcher; //導入方法依賴的package包/類
private static String getCorrectGroup(Matcher matcher) {
    for (int i = matcher.groupCount(); i > 0; i--) {
        final String group = matcher.group(i);
        if (group != null) {
            return group;
        }
    }
    throw new IllegalStateException("Group cannot be empty");
}
 
開發者ID:jhkst,項目名稱:dlface,代碼行數:10,代碼來源:MethodBuilder.java

示例6: fromString

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static MethodSignature fromString(String signatureString) {
    if (signatureString == null) {
        return null;
    }
    Matcher matcher = SIGNATURE_STRING_PATTERN.matcher(signatureString);
    if (matcher.find()) {
        if (matcher.groupCount() != 3) {
            throw new IllegalArgumentException("invalid signature");
        }
        return new MethodSignature(matcher.group(1), matcher.group(2), matcher.group(3).split(","));
    } else {
        throw new IllegalArgumentException("invalid signature");
    }
}
 
開發者ID:cadox8,項目名稱:PA,代碼行數:15,代碼來源:MethodWrapper.java

示例7: runNonTransparentProxyTest

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* runs the non transparent proxy test:
* 
* 1. open socket on requested port and send "OK" to let client continue the test 
* 2. wait for incoming HTTP protocol request
* 3. send request back to client (echo)
*  
   * @param command
   * @throws IOException 
   * @throws InterruptedException 
   */
  private void runNonTransparentProxyTest(String command) throws Exception {
int echoPort;

Pattern p = Pattern.compile(QoSServiceProtocol.CMD_NON_TRANSPARENT_PROXY_TEXT + " ([\\d]*)");
Matcher m = p.matcher(command);
m.find();
if (m.groupCount()!=1) {
	throw new IOException("non transparent proxy test command syntax error: " + command);
}
else {
	echoPort = Integer.parseInt(m.group(1));
}

try {
	TestServer.registerTcpCandidate(echoPort, socket);
	
	sendCommand(QoSServiceProtocol.RESPONSE_OK, command);
	TestServerConsole.log("NTP: sendind OK. waiting for request...", 1, TestServerServiceEnum.TCP_SERVICE);
}
catch (Exception e) {
	TestServerConsole.error(name, e, 1, TestServerServiceEnum.TCP_SERVICE);
}
finally {
	//is beeing done inside TcpServer now:
	//tcpServer.removeCandidate(socket.getInetAddress());
}
  }
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:39,代碼來源:ClientHandler.java

示例8: fromString

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Given a token string like 'T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX', creates a {@link WebHookToken} object.
 *
 * @param string {@link String} formatted like 'T????????/B????????/????????????????????????'
 * @return the {@link WebHookToken}
 * @throws IllegalArgumentException if the {@code string} is not a valid token
 */
public static WebHookToken fromString(String string) {
    Matcher matcher = TOKEN_PATTERN.matcher(string);
    if (matcher.find() && matcher.groupCount() == 3) {
        return WebHookToken.builder()
                .partT(matcher.group(1))
                .partB(matcher.group(2))
                .partX(matcher.group(3))
                .build();
    }
    throw new IllegalArgumentException(
            String.format("Unable to parse text as %s: %s", WebHookToken.class.getName(), string));
}
 
開發者ID:palantir,項目名稱:roboslack,代碼行數:20,代碼來源:WebHookToken.java

示例9: c_groups

import java.util.regex.Matcher; //導入方法依賴的package包/類
String c_groups(String input) {
	Matcher m = this.pattern.matcher(input);
	
	boolean r = m.find();
	if(!r) return null;
	
	StringBuilder builder = new StringBuilder();
	for(int i = 1; i <= m.groupCount(); i++) builder.append(m.group(i));
	return builder.toString();
}
 
開發者ID:gkatev,項目名稱:yify-subtitles,代碼行數:11,代碼來源:YifySub.java

示例10: findVersion

import java.util.regex.Matcher; //導入方法依賴的package包/類
private String findVersion(Pattern pattern) {
	WebView wv = new WebView(this.getApplicationContext());
	final String userAgent = wv.getSettings().getUserAgentString();
	if (userAgent != null) {
		final Matcher matcher = pattern.matcher(userAgent);
		if (matcher != null && matcher.find() && matcher.groupCount() == 2) {
			return matcher.group(2);
		}
	}
	return null;
}
 
開發者ID:fengshihao,項目名稱:WebPager,代碼行數:12,代碼來源:MainActivity.java

示例11: runRcvCommand

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
   * 
   * @param command
   * @param token
   * @throws IOException
   */
  private void runRcvCommand(String command, ClientToken token, boolean isIncoming) throws IOException {
Pattern p = Pattern.compile((isIncoming ? QoSServiceProtocol.REQUEST_UDP_RESULT_IN : QoSServiceProtocol.REQUEST_UDP_RESULT_OUT) + " ([\\d]*)");
Matcher m = p.matcher(command);
m.find();

if (m.groupCount()!=1) {
	throw new IOException("RCV command syntax error: " + command);
}
else {
	final int port = Integer.parseInt(m.group(1));
	sendRcvResult(isIncoming ? clientUdpInDataMap.get(port) : clientUdpOutDataMap.get(port), port, command);
}
  }
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:20,代碼來源:ClientHandler.java

示例12: saturate

import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override
public Collection<Name> saturate(Name name) {
	Matcher m = pattern.matcher(name.name);
	if (!m.matches())
		return Collections.emptyList();
	String[] groups = new String[m.groupCount() + 1];
	for (int i = 0; i < groups.length; ++i)
		groups[i] = m.group(i);
	Collection<Name> result = new ArrayList<Name>(formats.size());
	for (MessageFormat fmt : formats) {
		String s = fmt.format(groups);
		result.add(new Name(s, type));
	}
	return result;
}
 
開發者ID:Bibliome,項目名稱:bibliome-java-utils,代碼行數:16,代碼來源:SaturatePattern.java

示例13: getChineseCount

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static int getChineseCount(String str) {
    int count = 0;
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(str);
    while (m.find()) {
        for (int i = 0, groupCount = m.groupCount(); i <= groupCount; i++) {
            count = count + 1;
        }
    }
    return count;
}
 
開發者ID:Jusenr,項目名稱:androidtools,代碼行數:12,代碼來源:StringUtils.java

示例14: ApiResponse

import java.util.regex.Matcher; //導入方法依賴的package包/類
public ApiResponse(Response<T> response) {
  code = response.code();
  if (response.isSuccessful()) {
    body = response.body();
    errorMessage = null;
  } else {
    String message = null;
    if (response.errorBody() != null) {
      try {
        message = response.errorBody().string();
      } catch (IOException ignored) {

      }
    }
    if (message == null || message.trim().length() == 0) {
      message = response.message();
    }
    errorMessage = message;
    body = null;
  }
  String linkHeader = response.headers().get("link");
  if (linkHeader == null) {
    links = Collections.emptyMap();
  } else {
    links = new ArrayMap<>();
    Matcher matcher = LINK_PATTERN.matcher(linkHeader);

    while (matcher.find()) {
      int count = matcher.groupCount();
      if (count == 2) {
        links.put(matcher.group(2), matcher.group(1));
      }
    }
  }
}
 
開發者ID:charlesng,項目名稱:SampleAppArch,代碼行數:36,代碼來源:ApiResponse.java

示例15: getVersion

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static Version getVersion() {
    String name = Bukkit.getServer().getClass().getPackage().getName();
    String versionPackage = name.substring(name.lastIndexOf('.') + 1) + ".";
    for (Version version : values()) {
        if (version.matchesPackageName(versionPackage)) {
            return version;
        }
    }
    System.err.println("[ReflectionHelper] Failed to find version enum for '" + name + "'/'" + versionPackage + "'");

    System.out.println("[ReflectionHelper] Generating dynamic constant...");
    Matcher matcher = NUMERIC_VERSION_PATTERN.matcher(versionPackage);
    while (matcher.find()) {
        if (matcher.groupCount() < 3) {
            continue;
        }

        String majorString = matcher.group(1);
        String minorString = matcher.group(2);
        if (minorString.length() == 1) {
            minorString = "0" + minorString;
        }
        String patchString = matcher.group(3);
        if (patchString.length() == 1) {
            patchString = "0" + patchString;
        }

        String numVersionString = majorString + minorString + patchString;
        int numVersion = Integer.parseInt(numVersionString);
        String packge = versionPackage.substring(0, versionPackage.length() - 1);

        try {
            // Add enum value
            Field valuesField = new FieldResolver(Version.class).resolve("$VALUES");
            Version[] oldValues = (Version[]) valuesField.get(null);
            Version[] newValues = new Version[oldValues.length + 1];
            System.arraycopy(oldValues, 0, newValues, 0, oldValues.length);
            Version dynamicVersion = (Version) newEnumInstance(Version.class, new Class[]{
                    String.class,
                    int.class,
                    int.class}, new Object[]{
                    packge,
                    newValues.length - 1,
                    numVersion});
            newValues[newValues.length - 1] = dynamicVersion;
            valuesField.set(null, newValues);

            System.out.println("[ReflectionHelper] Injected dynamic version " + packge + " (#" + numVersion + ").");
            System.out.println("[ReflectionHelper] Please inform inventivetalent about the outdated version, as this is not guaranteed to work.");
            return dynamicVersion;
        } catch (ReflectiveOperationException e) {
            e.printStackTrace();
        }
    }

    return UNKNOWN;
}
 
開發者ID:cadox8,項目名稱:PA,代碼行數:58,代碼來源:Minecraft.java


注:本文中的java.util.regex.Matcher.groupCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。