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
5
votes
2 answers

Positive lookbehind vs non-capturing group: different behaviuor

I use python regular expressions (re module) in my code and noticed different behaviour in theese cases: re.findall(r'\s*(?:[a-z]\))?[^.)]+', 'a) xyz. b) abc.') # non-capturing group # results in ['a) xyz', ' b)…
aplavin
  • 2,199
  • 5
  • 32
  • 53
5
votes
1 answer

JavaScript regex back references returning an array of matches from single capture group (multiple groups)

I'm fairly sure after spending the night trying to find an answer that this isn't possible, and I've developed a work around - but, if someone knows of a better method, I would love to hear it... I've gone through a lot of iterations on the code,…
Patrick
  • 3,490
  • 1
  • 37
  • 64
5
votes
3 answers

REGEXP: capture group NOT followed by

I need to match following statements: Hi there John Hi there John Doe (jdo) Without matching these: Hi there John Doe is here Hi there John is here So I figured that this regexp would work: ^Hi there (.*)(?! is here)$ But it does not - and I am…
MatBos
  • 2,380
  • 24
  • 34
4
votes
1 answer

Excluding duplicates from a string in results

I am trying to amend this regex so that it does not match duplicates. Current regex: [\""].+?[\""]|[^ ]+ Sample string: ".doc" "test.xls", ".doc","me.pdf", "test file.doc" Expected results: ".doc" "test.xls" "me.pdf" But…
Darren Rose
  • 169
  • 13
4
votes
1 answer

Can I use regex capturing groups in SQL Server 2014?

I have some text data in an SQL Server 2014 table in which I want to detect complex patterns and extract certain portions of the text if the text matches the pattern. Because of this, I need capturing groups. E.g. From the text "Some title, Some…
Wouter
  • 1,829
  • 3
  • 28
  • 34
4
votes
3 answers

Vim / sed regex backreference in search pattern

Vim help says that: \1 Matches the same string that was matched by */\1* *E65* the first sub-expression in \( and \). {not in Vi} Example: "\([a-z]\).\1" matches "ata", "ehe", "tot", etc. It looks like the backreference…
Dave Grabowski
  • 1,619
  • 10
  • 19
4
votes
4 answers

Iterative regex capturing in C#

I have to read in a file that contains a number of coordinates. The file is structured in the following way: X1/Y1,X2/Y2,X3/Y3,X4/Y4 Where X and Y are positive integers. To solve this problem I want to use a regex (I think this is in general a good…
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
4
votes
1 answer

How do I use regular expression capturing groups with JFlex?

Although this question is about JFlex, it probably applies to other scanner generators such as lex, flex as well. If I have some rule, how can I create a capturing group in part of that rule and use the result of that captured group as an argument…
Zxaos
  • 7,791
  • 12
  • 47
  • 61
4
votes
1 answer

Is it possible to repeat a captured group in the substitution in regular expressions?

Is it possible with regex to repeat a captured group an amount of times with the added restriction that the amount to repeat is also found in a capture group? Example: Regex: /(a)([0-9])/g String: ba1na3na2 Expected result: banaaanaa I have never…
Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
4
votes
6 answers

Capturing and (thisPartOnly) with the same group

Let's say we have the following input: (bob) We also have the following regex: <(\w+)>|\((\w+)\) Now we get two matches (as seen on rubular.com): is a match, \1 captures amy, \2 fails (bob) is a match, \2 captures bob,…
polygenelubricants
  • 376,812
  • 128
  • 561
  • 623
4
votes
4 answers

Matching incremental digits in numbers

After googling many days about the issue, finally I am posting this question here and hoping to get it solved by experts here; I am looking for the regex pattern that can match incremental back references. Let me explain: For number 9422512322, the…
Gadara
  • 73
  • 4
4
votes
2 answers

Getting match of Group with Asterisk?

How can I get the content for a group with an asterisk? For example I'd like to pare a comma separated list, e. g. 1,2,3,4,5. private static final String LIST_REGEX = "^(\\d+)(,\\d+)*$"; private static final Pattern LIST_PATTERN =…
Vertex
  • 2,682
  • 3
  • 29
  • 43
4
votes
2 answers

How to get domain from a string using javascript regular expression

As the title suggests, I'm trying to retrieve the domain from a string using javascript regular expression. Take the following strings: String ==> Return "google" ==> …
Cheejyg
  • 336
  • 4
  • 12
3
votes
3 answers

Extract URL parameters with regex - repeating a capture group

I'm attempting to extract the URL parameters via regex and am sooo close to getting it to work. I even know what the problem is: my regex is stumbling on repeated capture groups. But I simply cannot figure out how to fix it. Language is PHP. My…
Zach
  • 9,591
  • 1
  • 38
  • 33
3
votes
4 answers

Why the line terminator `\r\n` causes groups not to be matched?

I'm working on text files with Windows line terminators (\r\n), on Linux with Perl v5.30. Something that I don't understand is why, with these text files, capturing groups don't match characters, while the regular expression matches. Example: $ echo…
Marcus
  • 5,104
  • 2
  • 28
  • 24
1 2
3
14 15