group « 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 » group 

1. Regex Named Groups in Java    stackoverflow.com

It is my understanding that the java.regex package does not have support for named groups (http://www.regular-expressions.info/named.html) so can anyone point me towards a third-party library that does? I've looked at ...

2. Java Regex Grouping Problem    stackoverflow.com

I'm trying to figure out a Java regex problem that I'm having. This is 1.6, but I don't think that matters. Anyway... I'm going to have some input data like ...

3. Java - Reg expression using groups    stackoverflow.com

From a string, I need to pull out groups that match a given pattern. An example string: <XmlLrvs>FIRST</XmlLrvs><XmlLrvs>SECOND</XmlLrvs><XmlLrvs>Third</XmlLrvs> Each group shall begin with <XmlLrvs> and end with </XmlLrvs>. Here is a snippet of ...

4. How to group in regex    stackoverflow.com

I have this input string(oid) : 1.2.3.4.5.66.77.88.99.10.52 I want group each number into 3 to like this Group 1 : 1.2.3 Group 2 : 4.5.66 Group 3 : 77.88.99 Group 4 : 10.52 It should be very ...

5. Java regex; conditions on groups    stackoverflow.com

I want to create a regex, where the occurence of one group, depends on whether or not another certain group has been found. I think this is easier to illustrate with ...

6. Regex to represent "NOT" in a group    stackoverflow.com

I have this Regex:

<(\d+)>(\w+\s\d+\s\d+(?::\d+){2})\s([\w\/\.\-]*)(.*)
What I want to do is to return FALSE(Not matched) if the third group is "MSWinEventLog" and returning "matched" for the rest.
<166>Apr 28 10:46:34 AMC the remaining phrase
<11>Apr ...

7. Does this regex have one or two groups? "^\\s*(.*?)\\s+-\\s+'(.*)'\\s*$"    stackoverflow.com

Does this regex have one or two groups? I'm trying to access the bookTitle using the second group but getting an error:

Pattern pattern = Pattern.compile("^\\s*(.*?)\\s+-\\s+'(.*)'\\s*$");
Matcher matcher = pattern.matcher("William Faulkner - 'Light In ...

8. Using captured regex group as argument to method    stackoverflow.com

Normally, when using regular expressions I can refer to a captured group using the $ operator, like so:

value.replaceAll("([A-Z])", "$1"); 
What I want to know is if it is somehow possible to ...

9. Java Regex for lines from /etc/passwd and /etc/group    stackoverflow.com

I've been working on a small Java problem set and have come across some trouble. I'm not very experienced writing regular expressions and could really use two for verifying line entries ...

10. Regex group question    stackoverflow.com

I have the string like this:

String s = "word=PS1,p1,p2,p3=q1,q2|word2=PS3,p4,p5,p6=q3";
or like this:
String s2 = "word3=PS2,p7,p8=q4,q5,q6|=PS3,p9=";
or like this:
String s3 = "=PS3=";
So, in formal - string contains some word defintintions in dictionary, splitted by ...

11. Parsing (and taking the group) for Regular Expression with repetition    stackoverflow.com

I tried to parse a rule using java and read whatever inside using RegEx, but since I am very new to RegEx, I found several problem. First, I try to parse a ...

12. Regex static group problem    stackoverflow.com

I have several strings in the rough form: [some number with one or 2 digits] [some text] [a text which is ABC or BC] [some text]

String test = "12testABCtest";
Pattern p = Pattern.compile("([\\d]{1,2})([\\w]*)(ABC|BC)([\\w]*)");
But ...

13. Java regex question with recursive groups    stackoverflow.com

I'm trying to parse from a string like below "name1(value1),name2(value2),name3(value3),name4(value4),........" and so it goes How can I do it recursively with groups?

14. Java regex question with groups    stackoverflow.com

I want to be able to parse below strings with a single regex using groups? There may or may not be single/multiple whitespace between dash and numbers. Input string examples:

"0.4 - ...

15. Java regular expression with groups    stackoverflow.com

I would like to replace all occurences of strings like:

"{something1}
"{someother2}
"{thing3}
but how to deal with group that contains string, not chars? -- edit: e.g. given String:
sometext "{something1}hello
I would like to have
sometext hello
or better, but its ...

16. Regular expression not returning the .group() value    stackoverflow.com

I'm new with java and using regular expressions. The method seems to be OK, and it's finding results on the subject string, but when I try to get the actual string ...

17. Regular expressions: some groups missing    stackoverflow.com

I have following Java code:

String s2 = "SUM   12  32 42";
Pattern pat1 = Pattern.compile("(PROD)|(SUM)(\\s+(\\d+))+");
Matcher m = pat1.matcher(s2);
System.out.println(m.matches());
System.out.println(m.groupCount());
for (int i = 1; i <=  m.groupCount(); ++i) {
  ...

18. Regex Issue With Multiple Groups    stackoverflow.com

I'm trying to create a regex pattern to match the lines in the following format:

field[bii] = float4:.4f_degree  // Galactic Latitude
field[class] = int2  (index) // Browse Object Classification
field[dec] = float8:.4f_degree ...

19. group counting issue with regex    stackoverflow.com

EDIT: The RE in the original code is irrelevant (or that it makes any sense). Let's say you're matching (X)|(Y): two patterns that are combined in the RE with an OR. ...

20. Please help with regular expressions, $ and illegal groups    coderanch.com

Hi there I am busy rebuilding php files after our translators have been at them. And I am trying to replace strings inside a file with new values. Here is the method that is giving me trouble public static String restoreDefines(StringBuffer original, Properties propertiesFile){ String answer = original.toString(); String key, value, define; for (Enumeration allKeys = propertiesFile.propertyNames(); allKeys.hasMoreElements() :wink: { key ...

21. Java regular expression grouping    coderanch.com

Hey, Given the following regex pattern: "(?:\\D*(\\d+)\\D*)*" and the following test cases: "12345" "a1234" "12a34" "1234a" I expect to see each test case result in a set of groups that maintain the original character order, and exclude any non-digit characters. My fallback is to iterate through the string char-by-char and build a new string skipping over non-numeric characters, but I am ...

22. Getting more than one result from regex groups    coderanch.com

Thanks to everyone in advance - I cannot seem to figure out why I wouldnt receive multiple groups back from this match. I would assume I would receive: [hello] [john] instead i am getting: [hello] [hello] It seems like the regex stops after the first match is found, which leads me to believe that it has to do with some sort ...

23. Regular expressions: Grouping    coderanch.com

(a side note: will look into ^ and $) private static boolean fourGroupPattern(String input) { int startGroupIndex = 1; String firstGroup="([a-zA-Z0-9 ]+)"; String secondGroup="([A-Z]-[A-Z])"; String thirdGroup="([0-9\\.x]+)"; String fourthGroup="([a-z, ()0-9+]+)"; String space="\\s"; pattern = firstGroup + space + secondGroup + space + thirdGroup + space + fourthGroup; Pattern p=Pattern.compile(pattern); Matcher matcher=p.matcher(input); if (matcher.matches()) { System.out.println("fourGroupPattern "+ input); for (int i=startGroupIndex; i<=matcher.groupCount(); i++) ...

25. regex - can't seem to get groups working correctly    forums.oracle.com

I think you have a fundamental misunderstanding. For a given regex the number of groups is set when the regex is compiled, not when the find() is executed. Your regex "(a(b)?)*" has two groups ALWAYS. Each time the find() produces a match you will have two groups. The group content can be empty but you will still have two groups.

26. Regular Expression Multiple grouping    forums.oracle.com

28. Regex - Group Counting    forums.oracle.com

29. Regex Groups    forums.oracle.com

30. REGEX_doubt_negating a group    forums.oracle.com

31. Using regex... problems with groups    forums.oracle.com

Now, I don't want all the 's in there. But I don't know how to avoid them. I need it widely grouped so that the + is included and I get all the codes instead of just one. Is there any kind of way to group the code within the ''s and then state that I want all of those bits ...

32. Java Regex groups with quantifiers.    forums.oracle.com

I'm a bit stuck on a regex , i want to do something similar to this : (dog){6} dogdogdogdogdogdog and returned I want 6 seperate groups with 'dog' in each one. This works fine with jakarta-regexp but when I use the {} quantifiers in Java regex I lose the groupings which i'm looking for and just get a single group with ...

33. RegExp and group    forums.oracle.com

Hi I'm currently working on an IDL compiler and was wondering if somebody can help me with a regular expression I use to read out methods from an IDL file. this.methodPattern = Pattern.compile(" s*" + "( w+)" + "\\s+(\\w+) s*" + "[\\(] s*" + "(?:(?:\\s*?(\\w+)\\s*(\\w+) s*?[,]?)?)*" + "[ )]" + "\\s*(?:\\s*raises\\s*( w+))?;"); Now this is supposed to match something like String ...

34. java.util.regex.PatternSyntaxException: Unclosed group near index XX    forums.oracle.com

871373 wrote: Am I overlooking something? I don't think so. I did a few experiments and get the same results as you do on 1.6.0_26 and on the latest 1.7 snapshot. I even tried it using Pattern.quote() rather then "\ \Qxxxxxxxx\ \E" but get the same result. I know very little about 'canonical equivalence' but since I expect one should be ...

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.