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
2 answers

How can I represent the regular language ∑={a,b,c} with a regular expression in such a way that two characters 'b' cannot be next to each other?

The alphabets of a regular language are ∑={a,b,c} I need create regular expression for: a.) Accepts strings that do not have two 'b' characters next to each other. example: aabccbaaccb <- allowed aabccbaaccbb <- not allowed b.) Accepts strings with…
0
votes
1 answer

REGEX: LineStrings (Geolocation) as named capture groups and also match line prefix

I have an input of lines of text, of which some contain relevant GeoData of Objects. I want to identify the relevant lines by matching a given prefix (that identifies the following coordinates as belonging to the desired Geo-Object). It may look…
Jannik Michel
  • 366
  • 1
  • 11
0
votes
0 answers

Remove consecutively repeated substring in a string using regex

import re input_text = "((PERS)Yo), ((PERS)Yo) ((PERS)yo) hgasghasghsa ((PERS)Yo) ((PERS)Yo) ((PERS)Yo) ((PERS)yo) jhsjhsdhjsdsdh ((PERS)Yo) jhdjfjhdffdj ((PERS)ella) ((PERS)Ella) ((PERS)ellos) asassaasasasassaassaas ((PERS)yo)…
Matt095
  • 857
  • 3
  • 9
0
votes
0 answers

How to solve error with look-arounds in a regex pattern based on replacements conditioned by the matching environment?

import re input_text = "Ellos son grandes amigos, pronto ellos se convirtieron en mejores amigos. ellos se vieron en el parque antes de llevar ((PERS)los viejos gabinetes), ya que ellos eran aun útiles para la compañía. Ellos son algo peores que…
Matt095
  • 857
  • 3
  • 9
0
votes
1 answer

How to perform string separations using regex as a reference and that a part of the used separator pattern is not removed from the following string?

import re sentences_list = ["El coche ((VERB) es) rojo, la bicicleta ((VERB)está) allí; el monopatín ((VERB)ha sido pintado) de color rojo, y el camión también ((VERB)funciona) con cargas pesadas", "El árbol ((VERB es)) grande, las hojas…
Matt095
  • 857
  • 3
  • 9
0
votes
0 answers

Split this string into substrings that are in middle of certain patterns, and within them a pattern and 3 different words, or more, from it?

I was trying several ways to divide these strings according to the separators that are in the separator_symbols variable, but only if the content in the middle meets the fact that there is a substring that meets the sequence of the pattern…
Matt095
  • 857
  • 3
  • 9
0
votes
3 answers

How do I regextract the second date in a string?

I am trying to extract the second date displayed in this string, however my code keeps extracting just the first date in gsheet: String: BOT +1 1/1 CUSTOM IWM 100 12 SEP 22/7 SEP 22 184/184 PUT/CALL @6.13 This is my code:…
0
votes
0 answers

matching sentence with word

I have a dataframe in which there is a column that contains text, and I have a list that consists of a group of words, and I want to make sure that one of the words in the list matches one of the words in the sentence and add it in a new column if…
arwa
  • 1
  • 1
0
votes
2 answers

Regex - Exclude URLs by keywords

I am trying to use StackPath's EdgeRules and their documentation is not very clear or good. I need to match urls in multiple directories but exclude any URL's that have the extension m3u8 in it or the word segment in it. This is their docs…
Panama Jack
  • 24,158
  • 10
  • 63
  • 95
0
votes
1 answer

Regex Quantifier Which Number of Occurrence Gets Tested First?

I'm completely new to regex and recently started learning it. Here's a part of my test string from which I'd like to find matches. 24 bit: Black #000000 12 bit: Black #000 My question is the following. When I use regex expression #(\w{1,2}), the…
jleng
  • 55
  • 1
  • 7
0
votes
1 answer

Why does Java's regex Pattern/Matcher miscount group positions in strings with unicode

I'm trying to use regular expressions and the strings include unicode characters such as '' and ''. The Pattern/Matcher are finding the expression I'm looking for but the Matcher returns the wrong position for the start of the match and thus also…
0
votes
0 answers

Prevent a regex with capturing groups from acting on matches of a string that re preceded by a specific word and at the same time succeeded by another

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

RegExp: find "cleverness" in a string

My RegExpression: ((^|\s)(clever)($|\s)) It finds "clever" in the string: clever or not yahoo clever but it doesn't find "clever" in this string: what means cleverness I don't want to bother you with the three other RegExp variations of my line…
seoux
  • 1
  • 1
0
votes
1 answer

Second optional capturing group depending on optional delimiter in regex

I'm sorry for asking this maybe duplicate question. I checked the existing questions and answers about optional capturing groups. I tried some things but I'm not able to translate the answer to my own example. This are two imput…
buhtz
  • 10,774
  • 18
  • 76
  • 149
0
votes
0 answers

Regex find replace in Visual Studio 2022

I'm trying to construct a VS22 Find Replace regex expression which will match a specific series of groups on lines of code, and use another expression to update those matching groups. The lines of code are something like this: [HttpGet,…
Matt W
  • 11,753
  • 25
  • 118
  • 215