Questions tagged [capture-group]
157 questions
0
votes
2 answers
Arbitrary number of capture groups in multiline strings
I have a long, Markdown-formatted string which consists of repeated sections of one or more headers and a multi-line description, like so:
**[Title1](link1) brief description** flag1, flag2
commentary,
occasionally multi-line
---
**[Title2](link2)…
![](../../users/profiles/2228091.webp)
Konrad
- 304
- 2
- 10
0
votes
1 answer
Regex: Multiple capture groups -- search and replace - DNS Logs
Stummped on a regex probelem and need a hand. Basically, I have DNS logs that come in like this:
8/21/2014 9:32:20 AM 0E5C PACKET 000000298F0CA280 UDP Rcv 10.2.56.13 136b Q [0001 D NOERROR] PTR …
![](../../users/profiles/450852.webp)
Josh
- 165
- 3
- 12
0
votes
2 answers
Capturing Groups REGEX Java
I'd like to capture the groups in my regular expression but it seems that I haven't written it as it should be. Consider the following lines:
String input = "username=johndoe";
Pattern pattern = Pattern.compile("(\\w+)=(\\w+)");
Matcher matcher =…
![](../../users/profiles/2397357.webp)
victorcmg
- 3
- 1
0
votes
1 answer
C++11 regex replace
I have an XML string that i wish to log out. this XML contains some sensitive data that i'd like to mask out before sending to the log file. Currently using std::regex to do this:
std::regex reg("(\\d*) ");
return…
![](../../users/profiles/1919930.webp)
markv
- 191
- 5
0
votes
2 answers
Perl search and replace with variable and capture group
As the question says, I am trying to do a search replace using a variable and a capture group. That is, the replace string contains $1. I followed the answers here and here, but they did not working for me; $1 comes through in the replace. Can you…
![](../../users/profiles/2505258.webp)
dseiple
- 530
- 6
- 16
0
votes
2 answers
regex capture groups returning as null after an OR operator
Matcher matcher = Pattern.compile("\\bwidth\\s*:\\s*(\\d+)px|\\bbackground\\s*:\\s*#([0-9A-Fa-f]+)").matcher(myString);
if (matcher.find()) {
System.out.println(matcher.group(2));
}
Example data:
myString =…
![](../../users/profiles/665518.webp)
meiryo
- 9,201
- 12
- 42
- 50
0
votes
1 answer
Javascript RegExp, fail in capture group
"aaa bbb ccc \n.000.\n 111".match(/^(?=\.).*(?=\.$)/m)
The result I am looking for in the above code is 000
but keeps giving me .000, note the dot before the zeros.
Works OK for the last dot but not for the first.
What am I missing?
![](../../users/profiles/422855.webp)
ZEE
- 2,131
- 3
- 25
- 35
-1
votes
1 answer
Pipe sed capture group through external program before replacing?
Is there a way for sed to pipe a capture group to another program, making \1 in the regexp's RHS equal to the output of that program?
For example, running
sed 's/lorem ipsum \(foobar\)/\1/g' file.txt
would pipe "foobar" through another program…
![](../../users/profiles/1429450.webp)
Geremia
- 2,736
- 25
- 31
-1
votes
2 answers
VIM regex capture group catches nothing
I am parsing some files using vim and would like to change the format of the following code.
Original format:
vmm_note(log, "TEST_DIR - BEGIN");
Desired format:
uvm_info("Test_seq", "TEST_DIR - BEGIN",UVM_LOW);
When this code is only one line, the…
![](../../users/profiles/7887073.webp)
peterj
- 33
- 1
- 3
-1
votes
1 answer
Regex capture group reference > repetition?
I am currently working on Regex Challenges on Hackerrank and can't find resources on to why using capture group references are preferred over repetitions.
Here is the link to the Challenge:…
![](../../users/profiles/8801157.webp)
pgoodbread
- 3
- 3
-1
votes
1 answer
Regular Expression (Captures to be used twice in a lookaround)
String is:
test1, test2, test3
Output required:
[b]Example Output:[/b] [url=https://urlhere=test1]test1[/url], [url=https://urlhere=test2]test2[/url], [url=https://urlhere=test3]test3[/url]
Is it possible with regular expressions to use the same…
![](../../users/profiles/8262102.webp)
Ste
- 752
- 1
- 5
- 18
-1
votes
1 answer
python regex not matching whitespace inside capture group
date_re = re.compile(r'^stuff (\d\d-\d\d\s)')
date_re.search('stuff 10-18 16:51').group(1)
Does not match because of the \s. If I remove the whitespace symbol the group will find the xx-xx digit pattern fine. What am I doing wrong with the space in…
![](../../users/profiles/1561108.webp)
user1561108
- 2,497
- 5
- 38
- 61
-1
votes
3 answers
Regex Return First Match
I have a weather file where I would like to extract the first value for "air_temp" recorded in a JSON file. The format this HTTP retriever uses is regex (I know it is not the best method).
I've shortened the JSON file to 2 data entries for…
![](../../users/profiles/8267846.webp)
Henry Blue
- 35
- 5
-1
votes
2 answers
Get value from a column with regex
I have lines of text similar to this:
value1|value2|value3 etc.
The values itself are not interesting. The type of delimeter is also unimportant, just like the number of fields. There could be 100 column, there could be only 5.
I would like to know…
![](../../users/profiles/4258642.webp)
Letokteren
- 589
- 1
- 6
- 25
-1
votes
1 answer
Java regex - Determine which capture group was matched and count occurences
Suppose that I want to build a very large regex with capture groups on run-time based on user's decisions.
Simple example:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
static boolean findTag,…
![](../../users/profiles/6031844.webp)
AndroidX
- 331
- 2
- 11