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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
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 ...
|
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 ...
|
|
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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
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?
|
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 - ... |
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 ... |
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 ... |
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) {
...
|
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 ...
|
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. ... |
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 ... |
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 ... |
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 ... |
(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++) ... |
|
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. |
|
|
|
|
|
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 ... |
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 ... |
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 ... |
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 ... |