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

Add letters with diacritics, and u with umlauts, to a pattern that captures strings tolerant of the rest of the letters

import re input_text = "Había... ; Martín Zázza no se trata de un nombre" #example 1 input_text = "asasjhsah; Carolina María Sol no se trataría de un nombre" #example 2 input_text = "Isaías no se trataría de un nombre" #example 3 word =…
Matt095
  • 857
  • 3
  • 9
0
votes
1 answer

Set regex pattern that concatenates one capture group or another depending on whether or not the input string starts with certain symbols

import re word = "" input_text = "Creo que July no se trata de un nombre" #example 1, should match with the Case 00 #input_text = "Creo que July Moore no se trata de un nombre" #example 2, should not match any case #input_text = "Efectivamente esa…
Matt095
  • 857
  • 3
  • 9
0
votes
1 answer

Define capture regex for name recognition of composite people connected by a connector

import re def register_new_persons_names_to_identify_in_inputs(input_text): #Cases of compound human names: name_capture_pattern = r"(^[A-Z](?:\w+)\s*(?:del|de\s*el|de)\s*^[A-Z](?:\w+))?" regex_pattern = name_capture_pattern +…
Matt095
  • 857
  • 3
  • 9
0
votes
1 answer

Set a multichoice regex to make its matching attempts always from left to right, no matter if another previous regex tries to capture more chars?

import re input_text = 'el dia corrimos juntas hasta el 11° nivel de aquella montaña hasta el 2022_-_12_-_13' #input_text = 'desde el corrimos juntas hasta el 11° nivel de aquella montaña y luego bajamos hasta la salida, hasta el 2022_-_12_-_01…
Matt095
  • 857
  • 3
  • 9
0
votes
1 answer

regex expression to replace everything in a string between 2 like characters?

This seems simple but I am not very familiar with regex so I'm having hard time finding a solution. I have a date/time in string format that looks like this: "11/18/2022 12:00 AM" I want to create another property that is just a day ahead (so…
0
votes
1 answer

create multiple rows from a single row based on operators with Pandas / regex in python

I have data which has many rows like this: | condition | result | | -------- | -------- | | ((a and b) or (c and d)) | Result A | | (a or b…
0
votes
1 answer

How to extract specific information with capture groups from an input string, rearrange and replace back inside this string using re.sub() function?

import re input_text = "estoy segura que empezaria desde las 15:00 pm del 2002_-_11_-_01 hasta las 16:00 hs pm" #example 1 input_text = "estoy segura que empezara desde las 15:00 pm h.s. del 2002_-_11_-_(01_--_15) hasta las 16:10 pm hs, aunque no…
Matt095
  • 857
  • 3
  • 9
0
votes
0 answers

PHP regex to fetch the inner function list from JavaScript source code

Below is the JavaScript source code on which the php regex I am trying to apply. I…
Amit Shah
  • 7,771
  • 5
  • 39
  • 55
0
votes
1 answer

Splite URI with regex

I am new in Regex. I want to splite my host URI like this:xxxPermanentWordChangeWord.myname.city.year.age i wnat to get: xxx and myname with one pattern regex i tried this var pattern = " (?=(?(.*)PermanentWord))?(?=(?i dont know what to…
0
votes
1 answer

Capture substring and send it to a function that modifies it and can replace it in this string

import re def one_day_or_another_day_relative_to_a_date_func(input_text): #print(repr(input_text)) #print what you have captured, and you should replace return "aaaaaaaa" def identify(input_text): some_text = r"(?:(?!\.\s*?\n)[^;])*" …
Matt095
  • 857
  • 3
  • 9
0
votes
0 answers

Why does this capture limit set with regex fail by modifying substrings that it shouldn't?

import re def date_to_internal_stored_format(input_text, identify_only_4_digit_years = False, limit_numbers_immediately_after_date = True): #grupo de captura para fechas en donde el año tiene si o si 4 digitos if…
Matt095
  • 857
  • 3
  • 9
0
votes
1 answer

How to get the only the digit using Regex expression from URL?

I need some help with Regex expression, as it s very new to me. I have a URL which consists of Item Number or Product ID. What I am looking to achieve is that could trim the URL part and extra part after a symbol of %. Here is how the url looks…
Riyaz Shaikh
  • 83
  • 11
0
votes
0 answers

How to use regex capturing-group in custom US Address information in Office365

I'm trying to create a custom U.S Address classification label in Azure Information Protection to match possible U.S Addresses Regex (it works Java8 - e.g. https://regex101.com/): ^(\d+) ?(\w)? (.*?) ?((?<=…
Raj
  • 13
  • 3
0
votes
2 answers

PHP preg_match_all returning blank strings in match group

I have the following string $string = "5A3BB0020221209DES.ACT"; And running the following Regex preg_match_all('/(00)|(?2\d{7}|\d{2}\.\d{2}\.\d{2}|\d{8}|\d{6})/', $string, $m); When I dump the output of $m['date'], I get an array like…
AdamMasters
  • 355
  • 3
  • 19
0
votes
1 answer

Parsing text using regex javascript

guys i am stuck while parsing following text into object. I have created two separate regex but i want to make only one. Below i am posting sample text as well as my following regex pattern. PAYER:\r\n\r\n MCNA \r\n\r\nPROVIDER:\r\n\r\n MY KHAN…