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

Extract value from QUERY_STRING to be used with AuthBasicFake directive

Apache 2.4.51. I need to extract a token from the QUERY_STRING and use it in a AuthBaiscFake directive. The incoming request is: GET /p000/vm/0/0?auth-token=HAI6i1eMT/uNeaIRpYw1Ww==&removable&readonly In the HTTPD configuration file, the end result…
Matt Muggeridge
  • 465
  • 3
  • 11
0
votes
4 answers

Obtain Regex matching Groups using Pattern.asPredicate()

Suppose that I have a list: List dest = Arrays.asList( "abc abd 2000", "idf owe 1200", "jks ldg 789", "ccc hhh 2000", "www uuu 1000" ); And I'm trying to get the number at the end of every string. The given list has only…
Javadkhan
  • 159
  • 2
  • 12
0
votes
1 answer

Regex Pattern: Start with X, contain Y, end with Z?

I have a configuration file for an application I've made, and to load the configurations I need to parse them from the config file first. I'm kind of stuck. Here is a snippet of the config…
qwerty
  • 383
  • 3
  • 7
  • 14
0
votes
0 answers

how to convert date in multiple character format into one standerd date format

I have a date file which has date in following format: 2017-01-04 00:00:00 (Y-d-m) 2017-03-22 00:00:00 (Y-m-d) 06/04/2017 (d/m-Y) When I import this into R it takes it as a character. I want to convert it into Date format,but…
0
votes
0 answers

Set lambda functions for reordering capturing groups extracted from an input string according to regex patterns that are indicated as their parameters

This is my code, and it is almost functional, with the exception of the 3 lambda functions in charge of the replacements and reordering of the string capture groups (day, month and year). I need help so that they can receive the necessary parameters…
Matt095
  • 857
  • 3
  • 9
0
votes
1 answer

Regex match repeated or similar lines in file

I'm trying to remove duplicated or similar lines, but I want to leave unselected only the last match, all duplicated or similar lines should be selected. This is the text I want to clean (ignore line number only to show at what line I'm…
Carlos P.
  • 43
  • 5
0
votes
1 answer

Remove the current year if another year was previously indicated after this regex pattern

This is my code where I indicate some possible examples to simulate the environment where this program will work import re, datetime #Example input cases input_text = '[26 -- 31] de 10 del 200 de 2022' #example 1 input_text = '[26 -- 31] de 12 del…
Matt095
  • 857
  • 3
  • 9
0
votes
2 answers

Delimiting string in R

I hope everyone is having a blast I have come to face this challange: I want to be able to extract one portion of a string in the folliing manner: The string may or may not have a dot or may have plenty of them I want to extract the string part…
R_Student
  • 624
  • 2
  • 14
0
votes
1 answer

Regex to find a word after a specific word and before a specific character

I am trying to pull the word that comes after "allignment=" pattern and before the next semi-colon occurance. I only want the first match in the text. An example text sample: "Testing all parameters. allignment=gate; Seach all the gateways.…
CanCoder
  • 3
  • 2
0
votes
1 answer

Regex returning empty list when trying to capture an optional group

I am trying to capture the board after every hand of a poker game. Each hand has a summary section in which the board is summarized as follows: string = "*** SUMMARY ***Total pot Rupees 971.44 | Rake Rupees 46.24Board [2s Qh 8s 7c]Seat 1: lesterr276…
0
votes
1 answer

Capture groups in 1 line with fixed delimiters

I'm a beginner at regex and still don't understand a lot. I apologize in advance from any wrong notations or missing information :( I need to extract groups from an e-mail subject where I have to use each value further on in a process to use as a…
Cor neetje
  • 21
  • 3
0
votes
0 answers

How to find the number of days in a month of a given year and replace it in a string if it meets the regex criteria?

import re, datetime from calendar import monthrange def date_standarization_03(match): input_text_substring = match.group() input_text_substring = input_text_substring.strip() #converts if it is indicated that it is "this month" to the…
Matt095
  • 857
  • 3
  • 9
0
votes
1 answer

Write a regex to find sentence inside the parentheses

I have to use regex inside C# program. Input string: WITH Sum_OrderQuantity_CTE AS (SELECT ProductKey, EnglishMonthName, SUM(OrderQuantity) AS TotalOrdersByMonth FROM [dbo].[FactInternetSales] fs INNER JOIN [dbo].[DimDate] dd ON dd.DateKey =…
0
votes
1 answer

Using replace() instead of xsl:analyze-string for a regex XSLT 2 3

I have an xsl:analyze-string() with a regular expression that works as desired.
Caroline
  • 167
  • 1
  • 11
0
votes
1 answer

capturing groups regex with cuantifiers

I'm using pandas.Series.str.extract function to extract year and quarter from strings. But I can not make to do it correctly. These are the strings that are in…
StandardIO
  • 156
  • 1
  • 7