Questions tagged [regex-group]

Regex groups are created by placing part of a regular expression inside parentheses. Groups allows to apply a quantifier to the entire group or to restrict alternation to part of the regex. Besides grouping part of a regular expression together, parentheses also create a numbered capturing group. It stores the part of the string matched by the part of the regular expression inside the parentheses.

The regex Set(Value)? matches Set or SetValue. In the first case, the first (and only) capturing group remains empty. In the second case, the first capturing group matches Value.

If capturing the match isn't needed, the regular expression can be optimized into Set(?:Value)?. The question mark and the colon after the opening parenthesis are the syntax that creates a non-capturing group.

The question mark after the opening bracket is unrelated to the question mark at the end of the regex. The final question mark is the quantifier that makes the previous token optional. This quantifier cannot appear after an opening parenthesis, because there is nothing to be made optional at the start of a group. Therefore, there is no ambiguity between the question mark as an operator to make a token optional and the question mark as part of the syntax for non-capturing groups.

2670 questions
0
votes
1 answer

How to use regexp_instr in Teradata such that start position of the search start at the end? Unlike INSTR its not taking -1 as position argument

How to use regexp_instr in Teradata such that start position of the search start at the end? Unlike INSTR its not taking -1 as position argument?I was trying to get the occurrence of a pattern from the end of a string. Unlike INSTR its not taking -1…
Souvik
  • 1
  • 1
0
votes
0 answers

How to capture all the substrings inside a string that start with an element of a list and end with another element of another list?

import re #input string capture_where_capsule = "alrededor ((NOUN)del auto rojizo, algo grande y completamente veloz). Luego dentro del baúl rápidamente abajo de una caja por sobre ello vimos una caña." #list of adverbs indicating the start of the…
Matt095
  • 857
  • 3
  • 9
0
votes
0 answers

VS Code Regex Find and Replace

with php8 I am now getting warnings on if statements with my variables. Current if ($var): echo $var; endif; Updated Format if (isset($var)): echo $var; endif; I am looking for a regex expression to wrap all instances of if ($var) and if($var) to if…
0
votes
0 answers

regex to cross over multiple lines with finditer

I am working on a regex that would parse the logs into groups to write into a df. Some of the log events break over multiple lines. I am doing this jupyter notebook I am trying to find a regex that looks forward for the start of the next line that…
newmember
  • 21
  • 2
0
votes
3 answers

How can I extract a specific column from a string table?

I have a text. How I can extract the Name column with JavaScript and RegExp? I have a code but that doesn't work correctly const stdout = `Name Enabled Description ---- ------- ----------- 6ytec …
0
votes
0 answers

Regex of replacements conditioned by previous regex patterns fails to capture any of the strings

import re input_text = "En esta alejada ciudad por la tarde circulan muchos camiones con aquellos acoplados rojos, grandes y bastante pesados, llevándolos por esos trayectos bastante empedrados, polvorientos, y un tanto arenosos. Y incluso bastante…
Matt095
  • 857
  • 3
  • 9
0
votes
1 answer

Regex matching a group that may or may not exist on string

I have a text which contains somewhere in the middle the following strings: Sat28 B158 RGX 1100 1200 Sat28 Hoover 0005 RGX B158 RGX 1100 1200 I want to capture only the following groups: Sat28 B158 RGX 1100 1200 Sat28 B158 RGX 1100 1200 To find…
leap
  • 7
  • 2
0
votes
2 answers

In Regex, how do I match until a char or another char indefinitely but don't group the last char?

This is my string, I want my regex to return "bash" at group 1 and "585602" at group 2 (the Pid value) Name: bash Umask: 0022 State: S (sleeping) Tgid: 585602 Ngid: 0 Pid: 585602 PPid: 585598 TracerPid: 0 Uid: 1000 1000 1000…
BaridunDuskhide
  • 107
  • 1
  • 5
0
votes
1 answer

(Resolved) Regex to select(replace) third and further duplicates of any string(s) in a single line

The Regex is intended for use in a Text-to-Speech program, which struggles with works that include stretched words or pronouncable-ish scenebreaks, like AAAAAAAAARRRRRRGGHHHH!!!! or XXXXXXXXXXXXXXXXXX, which while reading isn't an issue, the text to…
0
votes
1 answer

Why does this regex capture a maximum of 2 capture groups and not all those within the input string?

import re def verify_need_to_restructure_where_capsule(m): capture_where_capsule = str(m.group(1)) print(capture_where_capsule) return capture_where_capsule input_text = "Rosa está esperándote ((PL_ADVB='saassa')abajo). Estábamos…
Matt095
  • 857
  • 3
  • 9
0
votes
0 answers

How to capture two or more groups if they match to a pattern and are the same characters?

So I have the following set of lines: H23-H23 H23-H24 H23-K23 H23-K24 H23-N23 H23-N24 K23-H23 K23-H24 K23-K23 K23-K24 K23-N23 K23-N24 H24-H23 H24-H24 H24-K23 H24-K24 H24-N23 H24-N24 it falls under the following pattern…
0
votes
0 answers

Using regex to match multiple optional arguments in an enclosed custom function

I'm building a website and I have created a couple of custom functions that add certain information on the page. One of them is as follows: {{i|Custom argument 1|Custom argument 2|Custom argument 3|...|Custom argument n}} The number of arguments has…
OciXCrom
  • 11
  • 3
0
votes
1 answer

I am looking to do scraping of the website https://www.bananatic.com/es/forum/games/ and extract the tags "name", "views" and "replies". I have a big problem to get the non-empty content of the "name" tag. Can you help me? I need to save only the…
0
votes
1 answer

Capture all capitalized words in a row in a capture group only if they are before the end of the string or if they are before a punctuation mark or \n

import re def test_extraction_func(input_text): word = "" try_save_name = False #Not stop yet #Here I have tried to concatenate a substring at the end to try to establish it as a delimiter # that allows me to identify whether or…
Matt095
  • 857
  • 3
  • 9
0
votes
1 answer

Regex reset capture groups

I have tried alterations using '|' but seems to be impossible to first parse map if possible, if not, just parse the value as a whole, but keeping the capture group as no 1/2, tried with branch reset group but didn't manage that way either. Any…
Viktor Mellgren
  • 4,318
  • 3
  • 42
  • 75