pattern « group « Java Regex Q&A

Home
Java Regex Q&A
1.Development
2.find
3.group
4.Match
5.matcher
6.number
7.Operation
8.parse
9.Pattern
10.replace
11.validation
12.word
Java Regex Q&A » group » pattern 

1. How to get several regex groups from Matcher in Java?    stackoverflow.com

I have a Java program that does some String matching. I'm looking for anything that matches \d+x\d+ in a String. This works, using the Pattern and Matcher classes. However, to parse ...

2. Java Matcher groups: Understanding The difference between "(?:X|Y)" and "(?:X)|(?:Y)"    stackoverflow.com

Can anyone explain:

  1. Why the two patterns used below give different results? (answered below)
  2. Why the 2nd example gives a group count of 1 but says the start and end of group 1 is ...

3. How to appendReplacement on a Matcher group instead of the whole pattern?    stackoverflow.com

I am using a while(matcher.find()) to loop through all of the matches of a Pattern. For each instance or match of that pattern it finds, I want to replace matcher.group(3) ...

4. Identifying capture groups in a Regex Pattern    stackoverflow.com

Is there a way in Java (perhaps with an additional Open Source library) to identify the capture groups in a java.util.regex.Pattern (i.e. before creating a Matcher) Example from the Java docs:

...

5. java.util.regex.Matcher confused group    stackoverflow.com

I'm having trouble getting the right group of a regex match. My code boils down to following:

Pattern fileNamePattern = Pattern.compile("\\w+_\\w+_\\w+_(\\w+)_(\\d*_\\d*)\\.xml");
Matcher fileNameMatcher = fileNamePattern.matcher("test_test_test_test_20110101_0000.xml");

System.out.println(fileNameMatcher.groupCount());

if (fileNameMatcher.matches()) {
    for (int i ...

6. Java pattern matcher group definition    stackoverflow.com

I have a simple regular expression which looks something like

([a-z]*)( +[a-z]="[0-9]")*
and it works in matching patterns like
test a="1" b="2" c="3"...
Is there any way of capturing each of the name-value pairs (e.g., ...

7. Java Regex: matches(pattern, value) returns true but group() fails to match    stackoverflow.com

I have an odd problem with a regular expression in Java. I tested my Regex and my value here and it works. It says there are 3 groups (correct) ...

8. Java: Get group names using Pattern class?    stackoverflow.com

I am trying to use Pattern and Matcher class to extract matches out of a string. My string is as follows: $abc$12def$def$$11$ I want to get $abc$, $def$ and $11$ from this string. I ...

9. Topic: Regex problem for pattern and grouping    coderanch.com

Hi everyone, I have the following statement, "VARCHAR2 (a,2,c)", and the outputs I want are "a" , "2" and "c". There're two problems. 1) How can I ignore the "VARCHAR2 (" and ")" by using the pattern? 2) Can the extracted "a", "2", "c" in the same group? I can use subString & split to process it but I'm looking for ...

10. About Regex Pattern group?    forums.oracle.com

11. Regex group problem when $ is part of the pattern    forums.oracle.com

The problem comes from the fact that your replacement string (e.g. "${brown}") contains a $, which is treated by the appendReplacement as a back reference. Each occurrence of $g will be replaced by the result of evaluating group(g), where g must be a number between '0' and '9' (i.e. a valid capturing group number). In your case, g is '{', which ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.