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
3
votes
3 answers

Regex recursion captured string

I have a problem with a regex that has to capture a substring that it's already captured... I have this regex: (?\w+\.\w+)($|\/|\.) And I want to capture every subdomain recursively. For example, in this string: test1.test2.abc.def This…
Dugalle
  • 33
  • 2
3
votes
2 answers

PowerShell Regex: Capturing strings between two strings that is on multiple lines

I may have something like this: FIRST|[some text here] (newline) [insert text here] (newline) SECOND|A (newline) FIRST|[some text here] (newline) [insert text here] (newline) SECOND|B (newline) FIRST|[some text here] (newline) [insert text here]…
3
votes
2 answers

Wildcard in regular expression that is greedy only until a stop word

I am trying to build a 'simple' regular expression (in java) that matches sentences like these: I want to cook something I want to cook something with chicken and cheese I want to cook something with chicken but without onions I want to cook…
DataWorm
  • 73
  • 5
3
votes
4 answers

Regular expression capturing groups

With the following regular expression: InitValue\((\w*)\) and the test string: InitValue(Input1) I get the following result: Full match: InitValue(Input1) Group1: Input1 With the following regular expression: InitValue\((\w*)\s*,\s*(\w*)\) and…
Andy Rehn
  • 131
  • 6
3
votes
5 answers

Python re.sub() is not replacing every match

I'm using Python 3 and I have two strings: abbcabb and abca. I want to remove every double occurrence of a single character. For example: abbcabb should give c and abca should give bc. I've tried the following regex (here): (.)(.*?)\1 But, it gives…
vrintle
  • 5,501
  • 2
  • 16
  • 46
3
votes
2 answers

Non-greedy capturing parenthesis

I have the string mysql://user:pw@host/db?reconnect=true and the following (incorrect) regex: /^mysql:\/\/(.+):(.+)@(.+)\/(.+)\??.*$/ These are the matches I get: ["user", "pw", "host", "db?reconnect=true"] The only problematic match is…
Maxime Dupré
  • 5,319
  • 7
  • 38
  • 72
3
votes
1 answer

php preg_replace assign different replacement pattern for each capturing group

I'm trying to perform a mysql fulltext search in boolean mode and I need to prepare the search text before I build the mysql query. In order to achieve it, I though I could use the PHP function preg_replace and replace each capturing group by one…
3
votes
3 answers

Use of capturing group in .split() function

I have a string and i want to split it into array using the '|' character but not '\|': var a = 'abc\&|\|cba'; var b = a.split(/([^\\])\|/); result : b = ["abc", "&", "|cba"] expected output : b = ["abc\&", "\|cba"] Basically I cannot use…
3
votes
1 answer

How to re-use a capturing group to match a different alternation choice?

I have a group of words and another group with a conjunction. I’m looking for a regular expression that matches any single one of those words, demanding the conjunction in between: If the words are (A|B|C) and the conjunction is (&) then do match A…
dakab
  • 5,379
  • 9
  • 43
  • 67
3
votes
2 answers

Regular expression in Yahoo Pipes

I want to know what regular expression should be applied to replace 1 - 55 of 55 to only get 55 in Regex module of yahoo pipes. Thanks
Balaji
  • 31
  • 1
  • 4
3
votes
5 answers

Nested capturing groups result

How do I get an array like this [ 0: [ "first", "value", "1" ], 1: [ "second", "value", "2" ], 2: [ "third", "value", "3" ] ] or even better [ "first", "value", "1", "second", "value", "2", "third", "value", "3" ] from the…
Kamafeather
  • 8,663
  • 14
  • 69
  • 99
3
votes
1 answer

Problems with second argument of simple `replace()`

I don't understand, why doesn't this code work properly? "a-b".replace(/-(\w)/g, p1 => p1.toUpperCase()); // "a-B", instead of "aB" It has to be simplest solution for exchanging CSS's hyphen-syntax on camelCase.
Parzh from Ukraine
  • 7,999
  • 3
  • 34
  • 65
3
votes
2 answers

Java regex: extract function names

I'm trying to extract a list of function names from a formula, but my regex is not working. Given ( aaa(111) + bbb(222) ) / ccc ( 333 ) I need to obtain an array of strings containing aaa, bbb and ccc. Instead, I'm getting aaa(, bbb( and ccc (. how…
ps0604
  • 1,227
  • 23
  • 133
  • 330
3
votes
1 answer

Apache SSI capturing groups not working correctly?

Using Apache 2.4.10 (ap_expr in no legacy mode), the following SSI does not return the expected capturing group: