Questions tagged [capturing-group]

Capturing groups are regular expression constructs that makes use of capturing in regex to capture parts of the matched string during a match sequence in the regexp pattern.

Capturing groups and s are regular expression constructs that makes use of capturing in to perform matching and replacement that remembers parts of the matched string during a match sequence in the regexp pattern.

Read more:

223 questions
7
votes
2 answers

Regex that match exactly 3 identical consecutive numbers

Good morning all, I want to make a regex that match 3 same consecutive numbers. It should match only 3 numbers in a row (separated by a space), the numbers should be identical. If there are less or more than 3 same numbers, then the output should be…
Rol Co
  • 73
  • 3
7
votes
3 answers

Capture and execute multiline code and incorporate result in raku

This is a markdown document example.md I have: ## New language Raku is a new language different from Perl. ## what does it offer + Object-oriented programming including generics, roles and multiple dispatch + Functional programming primitives,…
Suman Khanal
  • 3,079
  • 1
  • 17
  • 29
6
votes
1 answer

SQL find-and-replace regular-expression capturing-group limit?

I need to convert data from a spreadsheet into insert statements in SQL. I've worked out most of the regular expressions for using the find and replace tool in SSMS, but I'm running into an issue when trying to reference the 9th parenthesized item…
6
votes
4 answers

How to use a regex to match if any pattern appears once out of many times in a given sequence

Hard to word this correctly, but TL;DR. I want to match, in a given text sentence (let's say "THE TREE IS GREEN") if any space is doubled (or more). Example: "In this text, THE TREE IS GREEN should not match, THE TREE IS GREEN should and so should…
6
votes
2 answers

How do I use more than nine backreferences in Notepad++ regexp?

If I use a long regular expression in Notepad++, i.e.: ^([^ ]+) ([^ ]+) ([^ ]+) (\[.*?\]) (".*?") (".*?") (".*?") (".*?") (\d+) (\d+) (\d+)$ (this is for turning an Apache log lines from space-separated to tab-separated) then I can't successfully…
watery
  • 5,026
  • 9
  • 52
  • 92
5
votes
3 answers

In Perl, is there a limit to the number of capture groups in a Regular Expression?

Is there a limit to the number of capture groups in a regular expression? I used to think it was 9 ($1 ... $9), but haven't found anything in the perlre docs to confirm this. And in fact, the following code shows that there are at least…
livefree75
  • 720
  • 8
  • 18
5
votes
3 answers

How to match all keys and values from a custom serialized object format?

I am trying to pick out all values from an object I have in string form. I have created the regular expression, but I am still having issues with not being able to remove the quotes and have hit a wall... Here is the code I have with results I get…
Oli C
  • 1,120
  • 13
  • 36
5
votes
1 answer

C++ regex: Get index of the Capture Group the SubMatch matched to

Context. I'm developing a Lexer/Tokenizing engine, which would use regex as a backend. The lexer accepts rules, which define the token types/IDs, e.g. = "\\b\\w+\\b". As I envision, to do the regex match-based tokenizing, all of the…
hakeris1010
  • 285
  • 1
  • 5
  • 12
5
votes
1 answer

regex: substitute character in captured group

EDIT In a regex, can a matching capturing group be replaced with the same match altered substituting a character with another? ORIGINAL QUESTION I'm converting a list of products into a CSV text file. Every line in the list has: number name[…
j.c
  • 2,825
  • 3
  • 31
  • 45
5
votes
2 answers

Regex: How to capture all iterations in repeated capturing group

I would expect these lines of C#: var regex = new Regex("A(bC*)*"); var match = regex.Match("AbCCbbCbCCCCbbb"); var groups = match.Groups; to return something like: ["AbCCbbCbCCCCbbb", "A", "bCC", "b", "bC", "bCCC", "b", "b", "b"] but instead it…
Reza Ahmadi
  • 862
  • 2
  • 11
  • 23
5
votes
2 answers

Regex - Saving Repeating Captured Group

This is what I'm doing a = "%span.rockets#diamonds.ribbons.forever" a = a.match(/(^\%\w+)([\.|\#]\w+)+/) puts a.inspect This is what I get # This is what I want #
Andrew Brown
  • 51
  • 1
  • 2
5
votes
1 answer

NSRegularExpression cannot find capturing group matches

I'm trying to parse a string using one regular expression pattern. Here is the pattern: (\")(.+)(\")\s*(\{) Here is the text to be parsed: "base" { I want to find these 4 capturing groups: 1. " 2. base 3. " 4. { I am using the following code…
Tomasz Szulc
  • 4,217
  • 4
  • 43
  • 79
5
votes
3 answers

Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators?

Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators? I'd specifically like to know if it's possible under the .NET Platform.
luvieere
  • 37,065
  • 18
  • 127
  • 179
5
votes
3 answers

regex - how to match group of unique characters of certain length

I'm looking for a regex that will match ad-hoc groups of characters of certain length only if all its characters are unique. For the given string example: 123132213231312321112122121111222333211221331 123, 132, 213, 231, 312, 321 are matched and…
caxekis
  • 63
  • 4
5
votes
2 answers

Regex only capturing last instance of capture group in match

I have the following regular expression in two different languages that produces the same odd results (javaScript and Flash). What I want to know is not how to fix it, but why the behavior is occurring? The Regular…
1
2
3
14 15