Named captures refers the the way a programmer can access the remembered and labeled parts of a string after a regex match.
Questions tagged [named-captures]
27 questions
32
votes
1 answer
Does Perl's `(?PARNO)` discard its own named captures when it's done?
Do recursive regexes understand named captures? There is a note in the docs for (?{{ code }}) that it's an independent subpattern with its own set of captures that are discarded when the subpattern is done, and there's a note in (?PARNO) that its…

brian d foy
- 129,424
- 31
- 207
- 592
10
votes
1 answer
What does the "+0" mean in the regexp \k?
I'm new to Regular Expressions in Ruby, and I can't seem to find any solid documentation on what \k means. It's the +0 part that I'm not getting.
Here's an example - this Regexp matches…

Aᴄʜᴇʀᴏɴғᴀɪʟ
- 2,957
- 4
- 24
- 50
7
votes
2 answers
multiple groups with the same name regex java?
Is there any regular expression api or library for java that can accept multiple groups with the same name in one pattern?

AIA
- 111
- 1
- 2
- 5
6
votes
3 answers
How do you destructure named capture groups?
In JavaScript, using named capture groups is pretty convenient:
const auth = 'Bearer AUTHORIZATION_TOKEN'
const { groups: { token } } = /Bearer (?[^ $]*)/.exec(auth)
console.log(token) // "AUTHORIZATION_TOKEN"
When I try that in typescript,…

Daniel Kaplan
- 62,768
- 50
- 234
- 356
3
votes
1 answer
How to access a capture group by name?
Say I have a MatchResult m:
>>> var m = Regex("(?hello) world").find("hello world")!!
How can I access the group named "foo" by name? According to the docs MatchGroupCollection implements the get(String) operator, but if I try it I get an…

Aran-Fey
- 39,665
- 11
- 104
- 149
3
votes
0 answers
Test Browser Compatibility for New Regular Expression Features
What's the best practice for determining if a browser supports the new regular expression features specified in the ECMAScript 2018 Language Specification?
I suspect you just have to write try catch statements or do it by detecting browser…

Lonnie Best
- 9,936
- 10
- 57
- 97
3
votes
2 answers
Python Regular Expression Named Capture Groups
Im learning regular expressions, specifically named capture groups.
Having an issue where I'm not able to figure out how to write an if/else statement for my function findVul().
Basically how the code works or should work is that findVul() goes…

kawhi_l02
- 81
- 1
- 5
3
votes
0 answers
Boost.regex with icu support using named capture groups
Below test program uses the named captures support in boost-regex to extract year, month and day fields from a date (just to illustrate the use of named captures):
#include
#include
#include
#include…

Geert Janssens
- 166
- 2
- 5
3
votes
1 answer
Java String.replaceAll backreference with named groups
How do you refer to named capture groups in Java's String.replaceAll method?
As a simplified example of what I'm trying to do, say I have the regex
\{(?\d\d\d\d):(?.*?)\}
which represents a tag in a string. There can be multiple tags…

Ruckus T-Boom
- 4,566
- 1
- 28
- 42
3
votes
1 answer
How do I force regex to match the longest possible part of the pattern.
I have a pattern in .net and I want a string be matched with longest possible part of the pattern
Pattern : "I (?[\w\W]*)(want to match (?longest))? available"
or "I ((?[\w\W]*)|(want to match (?longest))?)+ available"
String : "I want…

AIA
- 111
- 1
- 2
- 5
2
votes
2 answers
Only match IP addresses and not other numbers
I want the following regex code to return an output of IP addresses without returning other number values as IP from the source file.
The Code:
import re
logdata = 146.204.224.152 - feest6811 [21/Jun/2019:15:45:24 -0700] "POST /incentivize…

Mustapha
- 23
- 5
2
votes
1 answer
How do I extract and print both these named capture groups in perl?
I want to print both the gclid and the session named captures, but my regex is quitting as soon as it matches the gclid:
echo '"https://example.com/foo/?gclid=abc1234gef76786" session="765dsfsdf7657657khkjh"' | perl -nE…

jaygooby
- 2,436
- 24
- 42
2
votes
3 answers
Overlapping named capturing groups
I'm using named capturing groups to validate and extract data out of a product number. The format of the product number looks like this:
1102961D048.075
Chars 1-2 gender_code 11
Chars 1-6 style 110296
Chars 7-8 width_code …

dom
- 11,894
- 10
- 51
- 74
2
votes
2 answers
How can I create a conditional regex for a named capturing group?
We are looking to dump our PMDF logs into Splunk and I am trying to parse the PMDF SMTP logs, specifically the message, and I'm hitting an issue where a named capturing group (dst_channel) may or may not have a value. Here is my regex so…

user3723206
- 59
- 6
2
votes
1 answer
How to get Match Groups in ruby like Rubular without spliting the string
How does Rubular (Example) get the match groups?
/regex(? .*)/.match('some long string')
match method (in example) only returns the first match.
scan method returns an array without named captures.
What is the best way to get an array of…

Mo3z
- 2,138
- 7
- 21
- 29