Questions tagged [capture-group]

157 questions
2
votes
1 answer

Regex Match text within a Capture Group

Sample Text: \- !ruby/object:DynamicAttribute attributes: resource_id: "1" resource_type: Applicant string_value: "Michael" int_value: id: "35972390" date_value: name: first_name attributes_cache: {} \-…
Moody
  • 51
  • 1
  • 5
2
votes
2 answers

Assign capture groups to variables in XQuery

In many languages it is possible to assign regex capture groups to one or more variables. Is this also the case in XQuery? The best we got so far is doing a 'replace by capture group', but that doesn't seem the prettiest option. This is what we have…
Bram Vanroy
  • 22,919
  • 16
  • 101
  • 195
2
votes
2 answers

python re.sub - alternative replacement patterns

I want to provide alternative replacement patterns to re.sub. Let's say i've got two search patterns as alternatives, like this: re.sub(r"[A-Z]+|[a-z]+", replacementpattern, string) and instead of providing one replacement pattern I would like to…
2
votes
2 answers

java regex - capture repeated groups

I'm using Java's regex library. I want to validate a string against the following format: 31,5,46,7,86(...) The amount of numbers is not known. I want to make sure there is at least one number in that string, and that every two numbers are…
Roy Millo
  • 23
  • 1
  • 4
2
votes
2 answers

Trying to update a vimeo regex to get the ID from URL which includes "channels/staffpicks"

I have a vimeo regex which works in getting the ID from a standard URL: https://vimeo.com/42100325 I can't get it work when the URL is: https://vimeo.com/channels/staffpicks/142100325 This is what I have at the moment: var vimeoId =…
Jack Barham
  • 3,005
  • 7
  • 35
  • 57
2
votes
2 answers

Javascript regex: dynamic capture group

I'm trying to wrap my mind around regex for the first time. For the string I want you to MATCH THIS, you bastard regex, but also MATCH X THIS and yeah, MATCH X X X THIS too. Basically, a starting pattern, an end pattern and an arbitrary number of a…
Marek
  • 23
  • 3
2
votes
5 answers

Python re doesn't match last capture group

For the following code: t1 = 'tyler vs ryan' p1 = re.compile('(.*?) vs (.*?)') print p1.findall(t1) the output is: [('tyler', '')] but I would've expected this: [('tyler', 'ryan')] I have found that if I add a delimiter I can get it to work: t2…
Tyler
  • 15,509
  • 9
  • 45
  • 81
2
votes
1 answer

Cannot match specific group in JavaScript regex

regex101 JSFiddle I'm using the Rainbow.js library to add syntax highlighting to LaTeX code like so: Rainbow.extend('latex', [ { 'name': 'comment', 'pattern': /%.*$/gm }, { 'name': 'storage.function', …
Sean Allred
  • 3,206
  • 2
  • 28
  • 62
2
votes
3 answers

Valid RegEx with capture groups, but sed script not working

I have a valid RegEx pattern that captures three groups of a string. I'm trying to use it in a sed script to perform a find & replace operation, but I keep getting the following error: sed: -e expression #1, char 49: Unmatched ( or \( My script…
Shaun Scovil
  • 3,703
  • 4
  • 31
  • 54
2
votes
3 answers

Perl REGEX repetive capture groups when post processing output file

I am dealing with a string of numbers in scientific format. for example 24 6.924E+06 8.316E-01 1.052E-01 1.622E+01 1.311E+01 0.000E+00 6.059E-06 (snip.. extends for a bit) Now I want to write a regex for perl which allows me to capture the…
TheCodeNovice
  • 466
  • 8
  • 30
2
votes
1 answer

java regex split string with white space(except when both left and right was number or - )

I have this string how to split 5-28 14:00 - 5-28 18:00 the60s(.corp). I want to split it with white space except when the white space have number or - around them. The result I want was: 1. how 2. to 3. split 4. 5-28 14:00 - 5-28 18:00 5.…
Yinbin Wang
  • 113
  • 6
2
votes
2 answers

What is the purpose of non-matching groups

I was reading the Groovy tutorial and they talk about how you can create non-matching groups by leading the group off with ?:. This way the group will not come up on the matcher. What I dont understand is why you would want to explicitly say do not…
David says Reinstate Monica
  • 16,634
  • 19
  • 69
  • 108
2
votes
3 answers

Regex for matching different parts of a domain

I am attempting to split up domains into different categories (Subdomain, Domain, TLD) and am having trouble.. I can't figure out a way to match any number of subdomains and not overtake my domain or TLD mathcing. I am using PCRE regex. Current…
Stefan
  • 21
  • 2
2
votes
3 answers

C# Regex: How Can I Replace Tokens With Strings Generated at Run-time?

Given the following input and regex strings: const string inputString = "${Principal}*${Rate}*${Years}"; const string tokenMatchRegexString = @"\${([^}]+)}"; How can I replace each token (i.e. ${Principal}, ${Rate}, and ${Years}) with the return…
Jim G.
  • 14,056
  • 19
  • 94
  • 153
2
votes
2 answers

Python replace with re-using unknown strings

I have an XML in which I'd like to rename one of the tag groups like this: ABC unknown string should be ABC unknown string ABC is always the same, so that's no issue. However, "unknown…
Kaly
  • 2,489
  • 4
  • 19
  • 24