Regex: Repeated capturing groups
I have to parse some tables from an ASCII text file. Here's a partial sample:
QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212
RECKITTBEN 192.50 209.00 192.50 201.80 5.21 34 2850 5.707
RUPALIINS 150.00 159.00 150.00 156.25 6.29 4 80 .125
SALAMCRST 164.00 164.75 163.00 163.25 -.45 80 8250 13.505
SINGERBD 779.75 779.75 770.00 773.00 -.89 8 95 .735
SONARBAINS 68.00 69.00 67.50 68.00 .74 11 3050 2.077
The table consists of 1 column of text and 8 columns of floating point numbers. I'd like to capture each column via regex.
I'm pretty new to regular expressions. Here's the faulty regex pattern I came up with:
(S+)s+(s+[d.-]+){8}
But the pattern captures only the first and the last columns. RegexBuddy also emits the following warning:
You repeated the capturing group
itself. The group will capture only
the last iteration. Put a capturing
group around the repeated group to
capture all iterations.
I've consulted their help file, but I don't have a clue as to how to solve this.
How can I capture each column separately?
c# .net regex
add a comment |
I have to parse some tables from an ASCII text file. Here's a partial sample:
QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212
RECKITTBEN 192.50 209.00 192.50 201.80 5.21 34 2850 5.707
RUPALIINS 150.00 159.00 150.00 156.25 6.29 4 80 .125
SALAMCRST 164.00 164.75 163.00 163.25 -.45 80 8250 13.505
SINGERBD 779.75 779.75 770.00 773.00 -.89 8 95 .735
SONARBAINS 68.00 69.00 67.50 68.00 .74 11 3050 2.077
The table consists of 1 column of text and 8 columns of floating point numbers. I'd like to capture each column via regex.
I'm pretty new to regular expressions. Here's the faulty regex pattern I came up with:
(S+)s+(s+[d.-]+){8}
But the pattern captures only the first and the last columns. RegexBuddy also emits the following warning:
You repeated the capturing group
itself. The group will capture only
the last iteration. Put a capturing
group around the repeated group to
capture all iterations.
I've consulted their help file, but I don't have a clue as to how to solve this.
How can I capture each column separately?
c# .net regex
Which language are you using? In .NET it's easy.
– Tim Pietzcker
Jul 3 '10 at 19:42
@Tim: Yes I intend to write the program in C#. But at the moment, I'm prototyping it in Python.
– invarbrass
Jul 3 '10 at 20:01
See also: stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
Nice Pattern. Thanks
– Makah
May 10 '12 at 13:28
1
It can be retrieved with group captures. Take a look at stackoverflow.com/questions/11051558/…
– Marko Kukovec
May 8 '13 at 9:00
add a comment |
I have to parse some tables from an ASCII text file. Here's a partial sample:
QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212
RECKITTBEN 192.50 209.00 192.50 201.80 5.21 34 2850 5.707
RUPALIINS 150.00 159.00 150.00 156.25 6.29 4 80 .125
SALAMCRST 164.00 164.75 163.00 163.25 -.45 80 8250 13.505
SINGERBD 779.75 779.75 770.00 773.00 -.89 8 95 .735
SONARBAINS 68.00 69.00 67.50 68.00 .74 11 3050 2.077
The table consists of 1 column of text and 8 columns of floating point numbers. I'd like to capture each column via regex.
I'm pretty new to regular expressions. Here's the faulty regex pattern I came up with:
(S+)s+(s+[d.-]+){8}
But the pattern captures only the first and the last columns. RegexBuddy also emits the following warning:
You repeated the capturing group
itself. The group will capture only
the last iteration. Put a capturing
group around the repeated group to
capture all iterations.
I've consulted their help file, but I don't have a clue as to how to solve this.
How can I capture each column separately?
c# .net regex
I have to parse some tables from an ASCII text file. Here's a partial sample:
QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212
RECKITTBEN 192.50 209.00 192.50 201.80 5.21 34 2850 5.707
RUPALIINS 150.00 159.00 150.00 156.25 6.29 4 80 .125
SALAMCRST 164.00 164.75 163.00 163.25 -.45 80 8250 13.505
SINGERBD 779.75 779.75 770.00 773.00 -.89 8 95 .735
SONARBAINS 68.00 69.00 67.50 68.00 .74 11 3050 2.077
The table consists of 1 column of text and 8 columns of floating point numbers. I'd like to capture each column via regex.
I'm pretty new to regular expressions. Here's the faulty regex pattern I came up with:
(S+)s+(s+[d.-]+){8}
But the pattern captures only the first and the last columns. RegexBuddy also emits the following warning:
You repeated the capturing group
itself. The group will capture only
the last iteration. Put a capturing
group around the repeated group to
capture all iterations.
I've consulted their help file, but I don't have a clue as to how to solve this.
How can I capture each column separately?
c# .net regex
c# .net regex
edited Sep 6 '16 at 15:50
johnnyRose
4,116113552
4,116113552
asked Jul 3 '10 at 19:35
invarbrassinvarbrass
74541022
74541022
Which language are you using? In .NET it's easy.
– Tim Pietzcker
Jul 3 '10 at 19:42
@Tim: Yes I intend to write the program in C#. But at the moment, I'm prototyping it in Python.
– invarbrass
Jul 3 '10 at 20:01
See also: stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
Nice Pattern. Thanks
– Makah
May 10 '12 at 13:28
1
It can be retrieved with group captures. Take a look at stackoverflow.com/questions/11051558/…
– Marko Kukovec
May 8 '13 at 9:00
add a comment |
Which language are you using? In .NET it's easy.
– Tim Pietzcker
Jul 3 '10 at 19:42
@Tim: Yes I intend to write the program in C#. But at the moment, I'm prototyping it in Python.
– invarbrass
Jul 3 '10 at 20:01
See also: stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
Nice Pattern. Thanks
– Makah
May 10 '12 at 13:28
1
It can be retrieved with group captures. Take a look at stackoverflow.com/questions/11051558/…
– Marko Kukovec
May 8 '13 at 9:00
Which language are you using? In .NET it's easy.
– Tim Pietzcker
Jul 3 '10 at 19:42
Which language are you using? In .NET it's easy.
– Tim Pietzcker
Jul 3 '10 at 19:42
@Tim: Yes I intend to write the program in C#. But at the moment, I'm prototyping it in Python.
– invarbrass
Jul 3 '10 at 20:01
@Tim: Yes I intend to write the program in C#. But at the moment, I'm prototyping it in Python.
– invarbrass
Jul 3 '10 at 20:01
See also: stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
See also: stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
Nice Pattern. Thanks
– Makah
May 10 '12 at 13:28
Nice Pattern. Thanks
– Makah
May 10 '12 at 13:28
1
1
It can be retrieved with group captures. Take a look at stackoverflow.com/questions/11051558/…
– Marko Kukovec
May 8 '13 at 9:00
It can be retrieved with group captures. Take a look at stackoverflow.com/questions/11051558/…
– Marko Kukovec
May 8 '13 at 9:00
add a comment |
3 Answers
3
active
oldest
votes
In C# (modified from this example):
string input = "QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212";
string pattern = @"^(S+)s+(s+[d.-]+){8}$";
Match match = Regex.Match(input, pattern, RegexOptions.MultiLine);
if (match.Success) {
Console.WriteLine("Matched text: {0}", match.Value);
for (int ctr = 1; ctr < match.Groups.Count; ctr++) {
Console.WriteLine(" Group {0}: {1}", ctr, match.Groups[ctr].Value);
int captureCtr = 0;
foreach (Capture capture in match.Groups[ctr].Captures) {
Console.WriteLine(" Capture {0}: {1}",
captureCtr, capture.Value);
captureCtr++;
}
}
}
Output:
Matched text: QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212
...
Group 2: 1.212
Capture 0: 11.00
Capture 1: 11.10
Capture 2: 11.00
...etc.
Thanks for the heads up. I'm looking into the Group.Captures property.
– invarbrass
Jul 3 '10 at 20:06
2
Capturesis a neat feature, but it seems like overkill here. Why not just split each line on whitespace? Even if you use the regex to validate the format of the line, it's still less work.
– Alan Moore
Jul 4 '10 at 9:27
add a comment |
Unfortunately you need to repeat the (…) 8 times to get each column separately.
^(S+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)$
If code is possible, you can first match those numeric columns as a whole
>>> rx1 = re.compile(r'^(S+)s+((?:[-.d]+s+){7}[-.d]+)$', re.M)
>>> allres = rx1.findall(theAsciiText)
then split the columns by spaces
>>> [[p] + q.split() for p, q in allres]
1
Kenny, thanks for the prompt response! I'm actually using that pattern right now. But I was wondering if there's a better solution using repeating capturing groups.
– invarbrass
Jul 3 '10 at 19:41
@invarbrass: Not with repeated capturing groups that I'm aware of. Regexes often work best if you don't try to overdo them with a one-shot.
– Owen S.
Jul 3 '10 at 19:54
KennyTM: Thanks! Your solution works - I was doing something similar, albeit a lot less elegantly.
– invarbrass
Jul 3 '10 at 19:57
3
.NET is special in that it keeps intermediate captures! See Tim's answer and stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
add a comment |
If you want to know what the warning is appearing for, it's because your capture group matches multiple times (8, as you specified) but the capture variable can only have one value. It is assigned the last value matched.
As described in question 1313332, retrieving these multiple matches is generally not possible with a regular expression, although .NET and Perl 6 have some support for it.
The warning suggests that you could put another group around the whole set, like this:
(S+)s+((s+[d.-]+){8})
You would then be able to see all the columns, but of course they would not be separated. Because it's generally not possible to capture them separately, the more common intention is to capture all of it, and the warning helps remind you of this.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3172643%2fregex-repeated-capturing-groups%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
In C# (modified from this example):
string input = "QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212";
string pattern = @"^(S+)s+(s+[d.-]+){8}$";
Match match = Regex.Match(input, pattern, RegexOptions.MultiLine);
if (match.Success) {
Console.WriteLine("Matched text: {0}", match.Value);
for (int ctr = 1; ctr < match.Groups.Count; ctr++) {
Console.WriteLine(" Group {0}: {1}", ctr, match.Groups[ctr].Value);
int captureCtr = 0;
foreach (Capture capture in match.Groups[ctr].Captures) {
Console.WriteLine(" Capture {0}: {1}",
captureCtr, capture.Value);
captureCtr++;
}
}
}
Output:
Matched text: QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212
...
Group 2: 1.212
Capture 0: 11.00
Capture 1: 11.10
Capture 2: 11.00
...etc.
Thanks for the heads up. I'm looking into the Group.Captures property.
– invarbrass
Jul 3 '10 at 20:06
2
Capturesis a neat feature, but it seems like overkill here. Why not just split each line on whitespace? Even if you use the regex to validate the format of the line, it's still less work.
– Alan Moore
Jul 4 '10 at 9:27
add a comment |
In C# (modified from this example):
string input = "QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212";
string pattern = @"^(S+)s+(s+[d.-]+){8}$";
Match match = Regex.Match(input, pattern, RegexOptions.MultiLine);
if (match.Success) {
Console.WriteLine("Matched text: {0}", match.Value);
for (int ctr = 1; ctr < match.Groups.Count; ctr++) {
Console.WriteLine(" Group {0}: {1}", ctr, match.Groups[ctr].Value);
int captureCtr = 0;
foreach (Capture capture in match.Groups[ctr].Captures) {
Console.WriteLine(" Capture {0}: {1}",
captureCtr, capture.Value);
captureCtr++;
}
}
}
Output:
Matched text: QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212
...
Group 2: 1.212
Capture 0: 11.00
Capture 1: 11.10
Capture 2: 11.00
...etc.
Thanks for the heads up. I'm looking into the Group.Captures property.
– invarbrass
Jul 3 '10 at 20:06
2
Capturesis a neat feature, but it seems like overkill here. Why not just split each line on whitespace? Even if you use the regex to validate the format of the line, it's still less work.
– Alan Moore
Jul 4 '10 at 9:27
add a comment |
In C# (modified from this example):
string input = "QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212";
string pattern = @"^(S+)s+(s+[d.-]+){8}$";
Match match = Regex.Match(input, pattern, RegexOptions.MultiLine);
if (match.Success) {
Console.WriteLine("Matched text: {0}", match.Value);
for (int ctr = 1; ctr < match.Groups.Count; ctr++) {
Console.WriteLine(" Group {0}: {1}", ctr, match.Groups[ctr].Value);
int captureCtr = 0;
foreach (Capture capture in match.Groups[ctr].Captures) {
Console.WriteLine(" Capture {0}: {1}",
captureCtr, capture.Value);
captureCtr++;
}
}
}
Output:
Matched text: QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212
...
Group 2: 1.212
Capture 0: 11.00
Capture 1: 11.10
Capture 2: 11.00
...etc.
In C# (modified from this example):
string input = "QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212";
string pattern = @"^(S+)s+(s+[d.-]+){8}$";
Match match = Regex.Match(input, pattern, RegexOptions.MultiLine);
if (match.Success) {
Console.WriteLine("Matched text: {0}", match.Value);
for (int ctr = 1; ctr < match.Groups.Count; ctr++) {
Console.WriteLine(" Group {0}: {1}", ctr, match.Groups[ctr].Value);
int captureCtr = 0;
foreach (Capture capture in match.Groups[ctr].Captures) {
Console.WriteLine(" Capture {0}: {1}",
captureCtr, capture.Value);
captureCtr++;
}
}
}
Output:
Matched text: QSMDRYCELL 11.00 11.10 11.00 11.00 -.90 11 11000 1.212
...
Group 2: 1.212
Capture 0: 11.00
Capture 1: 11.10
Capture 2: 11.00
...etc.
answered Jul 3 '10 at 19:58
Tim PietzckerTim Pietzcker
248k43373458
248k43373458
Thanks for the heads up. I'm looking into the Group.Captures property.
– invarbrass
Jul 3 '10 at 20:06
2
Capturesis a neat feature, but it seems like overkill here. Why not just split each line on whitespace? Even if you use the regex to validate the format of the line, it's still less work.
– Alan Moore
Jul 4 '10 at 9:27
add a comment |
Thanks for the heads up. I'm looking into the Group.Captures property.
– invarbrass
Jul 3 '10 at 20:06
2
Capturesis a neat feature, but it seems like overkill here. Why not just split each line on whitespace? Even if you use the regex to validate the format of the line, it's still less work.
– Alan Moore
Jul 4 '10 at 9:27
Thanks for the heads up. I'm looking into the Group.Captures property.
– invarbrass
Jul 3 '10 at 20:06
Thanks for the heads up. I'm looking into the Group.Captures property.
– invarbrass
Jul 3 '10 at 20:06
2
2
Captures is a neat feature, but it seems like overkill here. Why not just split each line on whitespace? Even if you use the regex to validate the format of the line, it's still less work.– Alan Moore
Jul 4 '10 at 9:27
Captures is a neat feature, but it seems like overkill here. Why not just split each line on whitespace? Even if you use the regex to validate the format of the line, it's still less work.– Alan Moore
Jul 4 '10 at 9:27
add a comment |
Unfortunately you need to repeat the (…) 8 times to get each column separately.
^(S+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)$
If code is possible, you can first match those numeric columns as a whole
>>> rx1 = re.compile(r'^(S+)s+((?:[-.d]+s+){7}[-.d]+)$', re.M)
>>> allres = rx1.findall(theAsciiText)
then split the columns by spaces
>>> [[p] + q.split() for p, q in allres]
1
Kenny, thanks for the prompt response! I'm actually using that pattern right now. But I was wondering if there's a better solution using repeating capturing groups.
– invarbrass
Jul 3 '10 at 19:41
@invarbrass: Not with repeated capturing groups that I'm aware of. Regexes often work best if you don't try to overdo them with a one-shot.
– Owen S.
Jul 3 '10 at 19:54
KennyTM: Thanks! Your solution works - I was doing something similar, albeit a lot less elegantly.
– invarbrass
Jul 3 '10 at 19:57
3
.NET is special in that it keeps intermediate captures! See Tim's answer and stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
add a comment |
Unfortunately you need to repeat the (…) 8 times to get each column separately.
^(S+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)$
If code is possible, you can first match those numeric columns as a whole
>>> rx1 = re.compile(r'^(S+)s+((?:[-.d]+s+){7}[-.d]+)$', re.M)
>>> allres = rx1.findall(theAsciiText)
then split the columns by spaces
>>> [[p] + q.split() for p, q in allres]
1
Kenny, thanks for the prompt response! I'm actually using that pattern right now. But I was wondering if there's a better solution using repeating capturing groups.
– invarbrass
Jul 3 '10 at 19:41
@invarbrass: Not with repeated capturing groups that I'm aware of. Regexes often work best if you don't try to overdo them with a one-shot.
– Owen S.
Jul 3 '10 at 19:54
KennyTM: Thanks! Your solution works - I was doing something similar, albeit a lot less elegantly.
– invarbrass
Jul 3 '10 at 19:57
3
.NET is special in that it keeps intermediate captures! See Tim's answer and stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
add a comment |
Unfortunately you need to repeat the (…) 8 times to get each column separately.
^(S+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)$
If code is possible, you can first match those numeric columns as a whole
>>> rx1 = re.compile(r'^(S+)s+((?:[-.d]+s+){7}[-.d]+)$', re.M)
>>> allres = rx1.findall(theAsciiText)
then split the columns by spaces
>>> [[p] + q.split() for p, q in allres]
Unfortunately you need to repeat the (…) 8 times to get each column separately.
^(S+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)s+([-.d]+)$
If code is possible, you can first match those numeric columns as a whole
>>> rx1 = re.compile(r'^(S+)s+((?:[-.d]+s+){7}[-.d]+)$', re.M)
>>> allres = rx1.findall(theAsciiText)
then split the columns by spaces
>>> [[p] + q.split() for p, q in allres]
edited Jul 3 '10 at 19:48
answered Jul 3 '10 at 19:38
kennytmkennytm
403k79908917
403k79908917
1
Kenny, thanks for the prompt response! I'm actually using that pattern right now. But I was wondering if there's a better solution using repeating capturing groups.
– invarbrass
Jul 3 '10 at 19:41
@invarbrass: Not with repeated capturing groups that I'm aware of. Regexes often work best if you don't try to overdo them with a one-shot.
– Owen S.
Jul 3 '10 at 19:54
KennyTM: Thanks! Your solution works - I was doing something similar, albeit a lot less elegantly.
– invarbrass
Jul 3 '10 at 19:57
3
.NET is special in that it keeps intermediate captures! See Tim's answer and stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
add a comment |
1
Kenny, thanks for the prompt response! I'm actually using that pattern right now. But I was wondering if there's a better solution using repeating capturing groups.
– invarbrass
Jul 3 '10 at 19:41
@invarbrass: Not with repeated capturing groups that I'm aware of. Regexes often work best if you don't try to overdo them with a one-shot.
– Owen S.
Jul 3 '10 at 19:54
KennyTM: Thanks! Your solution works - I was doing something similar, albeit a lot less elegantly.
– invarbrass
Jul 3 '10 at 19:57
3
.NET is special in that it keeps intermediate captures! See Tim's answer and stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
1
1
Kenny, thanks for the prompt response! I'm actually using that pattern right now. But I was wondering if there's a better solution using repeating capturing groups.
– invarbrass
Jul 3 '10 at 19:41
Kenny, thanks for the prompt response! I'm actually using that pattern right now. But I was wondering if there's a better solution using repeating capturing groups.
– invarbrass
Jul 3 '10 at 19:41
@invarbrass: Not with repeated capturing groups that I'm aware of. Regexes often work best if you don't try to overdo them with a one-shot.
– Owen S.
Jul 3 '10 at 19:54
@invarbrass: Not with repeated capturing groups that I'm aware of. Regexes often work best if you don't try to overdo them with a one-shot.
– Owen S.
Jul 3 '10 at 19:54
KennyTM: Thanks! Your solution works - I was doing something similar, albeit a lot less elegantly.
– invarbrass
Jul 3 '10 at 19:57
KennyTM: Thanks! Your solution works - I was doing something similar, albeit a lot less elegantly.
– invarbrass
Jul 3 '10 at 19:57
3
3
.NET is special in that it keeps intermediate captures! See Tim's answer and stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
.NET is special in that it keeps intermediate captures! See Tim's answer and stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
add a comment |
If you want to know what the warning is appearing for, it's because your capture group matches multiple times (8, as you specified) but the capture variable can only have one value. It is assigned the last value matched.
As described in question 1313332, retrieving these multiple matches is generally not possible with a regular expression, although .NET and Perl 6 have some support for it.
The warning suggests that you could put another group around the whole set, like this:
(S+)s+((s+[d.-]+){8})
You would then be able to see all the columns, but of course they would not be separated. Because it's generally not possible to capture them separately, the more common intention is to capture all of it, and the warning helps remind you of this.
add a comment |
If you want to know what the warning is appearing for, it's because your capture group matches multiple times (8, as you specified) but the capture variable can only have one value. It is assigned the last value matched.
As described in question 1313332, retrieving these multiple matches is generally not possible with a regular expression, although .NET and Perl 6 have some support for it.
The warning suggests that you could put another group around the whole set, like this:
(S+)s+((s+[d.-]+){8})
You would then be able to see all the columns, but of course they would not be separated. Because it's generally not possible to capture them separately, the more common intention is to capture all of it, and the warning helps remind you of this.
add a comment |
If you want to know what the warning is appearing for, it's because your capture group matches multiple times (8, as you specified) but the capture variable can only have one value. It is assigned the last value matched.
As described in question 1313332, retrieving these multiple matches is generally not possible with a regular expression, although .NET and Perl 6 have some support for it.
The warning suggests that you could put another group around the whole set, like this:
(S+)s+((s+[d.-]+){8})
You would then be able to see all the columns, but of course they would not be separated. Because it's generally not possible to capture them separately, the more common intention is to capture all of it, and the warning helps remind you of this.
If you want to know what the warning is appearing for, it's because your capture group matches multiple times (8, as you specified) but the capture variable can only have one value. It is assigned the last value matched.
As described in question 1313332, retrieving these multiple matches is generally not possible with a regular expression, although .NET and Perl 6 have some support for it.
The warning suggests that you could put another group around the whole set, like this:
(S+)s+((s+[d.-]+){8})
You would then be able to see all the columns, but of course they would not be separated. Because it's generally not possible to capture them separately, the more common intention is to capture all of it, and the warning helps remind you of this.
edited May 23 '17 at 12:09
Community♦
11
11
answered Jan 2 '11 at 9:12
Sam BrightmanSam Brightman
1,41832126
1,41832126
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3172643%2fregex-repeated-capturing-groups%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Which language are you using? In .NET it's easy.
– Tim Pietzcker
Jul 3 '10 at 19:42
@Tim: Yes I intend to write the program in C#. But at the moment, I'm prototyping it in Python.
– invarbrass
Jul 3 '10 at 20:01
See also: stackoverflow.com/questions/3029127/…
– polygenelubricants
Jul 4 '10 at 7:59
Nice Pattern. Thanks
– Makah
May 10 '12 at 13:28
1
It can be retrieved with group captures. Take a look at stackoverflow.com/questions/11051558/…
– Marko Kukovec
May 8 '13 at 9:00