Questions tagged [capture-group]
157 questions
4
votes
1 answer
How to capture 'multiple' repeated groups with Regular Expressions
I have the following text file I would like to parse out to get the individual fields:
host_group_web = ( )
host_group_lbnorth = ( lba050 lbhou002 lblon003 )
The fields that I would like to extract are in bold
host_group_web = (…
![](../../users/profiles/962561.webp)
mindrunner
- 121
- 1
- 7
4
votes
1 answer
Get error when try to use `\1` which get from regex `(\d)?` in Python
Example code:
#!/usr/bin/env python
import re
print re.sub(r'a+(\d)?', r'\1', "aaaa3")
print re.sub(r'a+(\d)?', r'\1', "aaaa") # error!
The second print statement gives me an error:
3
Traceback (most recent call last):
File "./bbb.py", line 5,…
![](../../users/profiles/829496.webp)
fronthem
- 3,617
- 5
- 26
- 49
4
votes
1 answer
Why is my regex capture group only capturing the last part of the string when it matches multiple parts?
What I Tried
var test = "asdfdas ABCD EFGH";
var regex = /^\S+( [A-Z]{4})+$/;
// Also tried: /^\S+( [A-Z]{4})+$/g
// And: /^\S+( [A-Z]{4})+?$/g
var matches = test.match(regex);
I made a JSFiddle.
What I Expect
The variable matches should…
![](../../users/profiles/1169991.webp)
NoBrainer
- 5,360
- 1
- 22
- 25
4
votes
2 answers
Do the following capture group notation mean something to Perl
In the following why does the condition evaluate to false?
$_ = "aa11bb";
if(/(.)\111/){
print "It matched!\n";
}
Does \11 or \111 have special meaning that Perl can not "see" \1?
![](../../users/profiles/1197249.webp)
Jim
- 17,102
- 31
- 115
- 227
3
votes
1 answer
Replace multiple captured groups in regex
VB2005: I've been looking at regex for some hours now and cant seem to get my head around the .Replace for my case. I'm looking for two fields and then I want to replace those fields with new values. So my string looks like so:
Dim myInputString as…
![](../../users/profiles/428507.webp)
sinDizzy
- 1,156
- 6
- 22
- 55
3
votes
2 answers
How can I get the count of a capture group then replace the characters with a specific character?
How can I get the count of a capture group and replace it with the same number of characters that I specify?
For example here is a string...
123456789ABCD00001DDD
My regex with capture groups is as…
![](../../users/profiles/1039753.webp)
Arvo Bowen
- 3,742
- 6
- 37
- 78
3
votes
1 answer
Java Regex - capture string with single dollar, but not when it has two successive ones
I posted this question earlier.
But that wasn't quite the end of it.
All the rules that applied there still apply.
So the strings:
"%ABC%" would yield ABC as a result (capture stuff between percent signs)
as would "$ABC." (capture stuff after $,…
![](../../users/profiles/495157.webp)
JGFMK
- 7,107
- 4
- 46
- 80
3
votes
4 answers
regex replace parts/groups of a string in R
Trying to postprocess the LaTeX (pdf_book output) of a bookdown document to collapse biblatex citations to be able to sort them chronologically using \usepackage[sortcites]{biblatex} later on. Thus, I need to find }{ after \\autocites and replace it…
![](../../users/profiles/11460221.webp)
rnuske
- 63
- 6
3
votes
1 answer
Regex to capture unknown number of repeated groups
I'm try to write a regular expression to use in a Java program that will recognize a pattern that may appear in the input an unknown number of times. My silly little example is:
String patString = "(?:.*(h.t).*)*";
Then I try to access the matches…
![](../../users/profiles/514757.webp)
umbraphile
- 377
- 2
- 5
- 15
3
votes
2 answers
sed - print translated HEX using capture group
I would like to print directly with sed a HEX value translation by isolating the HEX values in capture groups. This works:
echo bbb3Accc | sed -n 's/3A/\x3A/p'
bbb:ccc
...but this doesn't work:
echo bbb3Accc | sed 's/\(3A\)/\x\1/'
bbbx3Accc
...or…
![](../../users/profiles/3130850.webp)
one-liner
- 761
- 1
- 8
- 19
3
votes
1 answer
How can I do multiple replace using a shared backreference?
I have a need to do some data-transformation for data load compatibility. The nested key:value pairs need to be flattened and have their group id prepended to each piece of child data.
I've been trying to understand the page at
Repeating a…
![](../../users/profiles/601131.webp)
rumpled
- 43
- 5
3
votes
1 answer
Regex URL Capturing Group
I'm writing a regex expression and trying to get each part of a URL into it's own capture group for extraction:
Protocol (http,https)
Sub Domain (sub)
Domain (domain)
Domain Extension (com,net)
Path (/path/to/file - this is to be the path to the…
user7892649
3
votes
3 answers
Python regular expression returning extra capture group for last character matched
I am trying to create a regular expression that will take strings and break them up into three groups: (1) Any one of a specific list of words at the beginning of a string. (2) Any one of specific list of words at the end of a string. (3) all of…
![](../../users/profiles/176410.webp)
J. Taylor
- 3,488
- 2
- 22
- 48
3
votes
4 answers
extract last match from string in c#
i have strings in the form [abc].[some other string].[can.also.contain.periods].[our match]
i now want to match the string "our match" (i.e. without the brackets), so i played around with lookarounds and whatnot. i now get the correct match, but i…
![](../../users/profiles/112968.webp)
knittl
- 197,664
- 43
- 269
- 318
3
votes
2 answers
Get $1 capture group with dynamic RegExp
I was curious if anyone knows what I'm doing wrong here. I want to use a variable inside the expression but for some reason when I try to, it doesn't seem to grab the search term with the $1.
This returns correctly:
$('.content').html(function(_,i)…
![](../../users/profiles/1524879.webp)
daless14
- 67
- 5