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 establish in this code the condition of <> enters a code block and not another

This is an example of input string: import re input_text = "Hello, I will dictate the following numbers in Spanish, write them down ochocientos veinti-ocho sete cientos quince dieci siete dieci-seis,ochocientos veinti ocho" Here are the 3…
Matt095
  • 857
  • 3
  • 9
0
votes
1 answer

Regex match a string followed by 1 forward slash

I need to match a string with alphanumeric, underscores and dashes only followed by one or zero forward slash only. These are valid: aBc ab-9/ a_C-c/ 3-b-c These are invalid: aBc/xyz 1bc/x7z/ hello// a-b_/89u/13P I am trying…
0
votes
0 answers

Regex to find pattern STRING/STRING, with word exception

I am working with urls. I need to find a regex that catches strings like this: string/string/ -OR- string/string But there is an exception. The first string cannot be "brand" nor "category" (but the second can be). The second forward slash is…
0
votes
1 answer

Possible to differentiate different GCP logging policies/incidents with a regex?

I am using a Log Match Condition to trigger a GCP alert policy which contains a string match for the text in my firebase function log, e.g. textPayload =~ "^My Trigger: (.*)$" This is working a treat, but I really want to trigger different…
Fringley
  • 876
  • 1
  • 8
  • 6
0
votes
1 answer

Regex: Match pattern unless preceded by pattern containing element from the matching character class

I am having a hard time coming up with a regex to match a specific case: This can be matched: any-dashed-strings this-can-be-matched-even-though-its-big This cannot be matched: strings starting with elem- or asdf- or a single…
ghaschel
  • 1,313
  • 3
  • 20
  • 41
0
votes
1 answer

Regex to match multiple phrases between known words

I am trying to match multiple phrases between known words. Essentially, I want to parse out what the user filled in inside the brackets: Get information for [name] for [duration] for [location]. I want to obtain what the user entered for name,…
0
votes
1 answer

How to make this regex ((?:\w\s*)+) extract substrings that include dots, commas and/or line breaks?

how to make this regex grab the entire string in the middle without being cut if it detects, points., commas ,, colons : or semicolons; The only case where the regex should not grab the text is if there is a line break between the set ends import…
Matt095
  • 857
  • 3
  • 9
0
votes
2 answers

Regex matching multiple groups

I am very new to Regex and trying to create filter rule to get some matches. For Instance, I have query result like…
WinterMute
  • 145
  • 2
  • 11
0
votes
1 answer

Detect a pattern and extract numeric values to then evaluate them and in certain cases replace their modifications in their original position

import re input_text = "entre las 15 : hs -- 16:10 " #Example 1 input_text = "entre las 21 : -- 22" #Example 2 input_text = "entre la 1 30 -- 2 " #Example 3 input_text = "entre la 1 09 h.s. -- 6 : hs." #Example 4 input_text = "entre la 1:50 --…
Matt095
  • 857
  • 3
  • 9
0
votes
2 answers

Regex capture multi-line groups

I'm struggling in creating a regex to capture what's included between two keywords in a multi-line file. In particular, consider the following file: #%META # date: 2022-08-27 # generated-by: Me # id: 1 #%ENDS #%BODY .... #%ENDS #%META # date:…
andrew-94
  • 27
  • 4
0
votes
2 answers

using Regex how do I capture the exception message only without stack trace

I have this text: System.FormatException: String '' was not recognized as a valid DateTime. at Application.Mappers.AutoMapperProfile.<>c.<.ctor>b__0_92(CartCampaignDto x, CartCampaign y) in /build/src/Application/Mappers/AutoMapperProfile.cs:line 60…
Nour
  • 5,252
  • 3
  • 41
  • 66
0
votes
0 answers

regex allow first letter to be number

I am using the following regex. /^(([0-9._]?)*([a-zA-Z._]|[a-zA-Z._][a-zA-Z0-9\-._]*[a-zA-Z0-9])\._)*([A-Za-z._]|[A-Za-z._][A-Za-z0-9\-._]*[A-Za-z0-9_])$/; It fails for 1dsd.343.23fdf but passes d1sd.343.23fdf what is to be modified on the regex to…
Rohit Kumar
  • 1,777
  • 2
  • 13
  • 26
0
votes
2 answers

Python RegEx: Extract timestamp between Square brackets

I have a source data which is given below:- 14.284.2.1572 - feest6811 [21/Jun/2019:15:45:24 -0700] "POST /incentivize HTTP/1.1" 302 4622 187.109.797.1798 - kertzmann3129 [21/Jun/2019:15:45:25 -0700] "DELETE /virtual/solutions/target/web+services…
Vibhor Gupta
  • 670
  • 7
  • 16
0
votes
1 answer

Finding a field and replacing the first 16 digits of the field_value [string] with Regex

I am able to find similar question here on the site but not one specific that will help me fix my issue. I want to mask all but the last 4 digits of cardNo value coming in the request while Logging. Ex. if it is "cardNo":"10929291929312911131" then…
0
votes
1 answer

Regular Expressions. Find unknown length string excluding character combinations

I am new to regex and I spent half of my day to solve this question. I tried to search for answers, but couldn't find similar example. I need to match strings if their end does not include char combinations such as (L|R|MIR).. My…