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

Regex for repeated pattern separated by comma

Hey so I would like to generate a regex that repeats a pattern (\w*:\w*) separated by a comma. I will include some valid and invalid patterns to see in the following: Valid: SomeAlpha:Abc Valid: Aa:Bb,Cc:Dd,Ee:Ff,Gg:Hh Invalid:…
appix
  • 29
  • 3
0
votes
0 answers

How do I modify the following regex to match on the first occurrence of a digit in a year (e.g. 2020)?

I have the following regex expression but it fails to match on only the 1st occurrence of the digit "2": (?<=[a-zA-Z0-9])[2A-Z] For example, if I use the string "fifa2020" it will match on both 2's. I only want it to match on the first 2. How do I…
d2learner
  • 3
  • 1
0
votes
1 answer

Regex: How to avoid capturing a group if it ends with a specific character

I need to avoid capturing a match if it ends with a colon. Example below: item: something item: another item: things: item: yetanother My desired result is to return nothing from the 3rd line. I feel like I'm close with this regex using…
kaizen
  • 9
  • 2
0
votes
1 answer

How to build this regex so that it extracts a word that starts with a capital letter if only if it appears after a previous pattern?

I need a regex that extracts all the names (we will consider that they are all the words that start with a capital letter and respect having certain conditions prior to their appearance within the sentence) that are in a sentence. This must be done…
user15898019
0
votes
1 answer

Regex ignore nested matched

I am trying to parse nested data types. Examples: ARRAY, MAP. When I have an array, I use that regex ^ARRAY<(.*)>$. Regex returns one group with a data type. When I have a map, I use that regex ^MAP<(.*),(.*)>$. Regex…
0
votes
2 answers

Match a line break on the line before another match

I have a file with the following pattern: A = 1 B = 2 C = 3 A = 10 B = 20 C = 30 I would like match only the line break before A = * My attempt would also matches A = * as well as the line break Code: [\r\n]+.*A.* But I only need the line break…
Kevin_ALA
  • 233
  • 2
  • 11
0
votes
2 answers

Parsing text file into csv. Issue splitting string that spans across multiple lines via PowerShell regex

I'm attempting to parse a txt file into a csv with 4 headers. However, I'm having some troubles successfully splitting/matching text between two strings that spans across multiple lines. I'm not very experienced with regex. Is there a way to do this…
Devinput
  • 53
  • 1
  • 7
0
votes
1 answer

Express Router with nested params doesn't work

I have a working example that matches the desired route path, but I have to recreate the full file name in the controller from the param 'cameraname' and the knowing the rest of the filename. Here's the code that works like that: this.router.get( …
Mark W.
  • 25
  • 2
0
votes
1 answer

include unicode character within long regex

I have a regex: /[a-zA-Zɑôáīúȑìêɑ͡iɑ͡uŋġḧn̐ƞġg̶̃čḣñt́d́ŕŕńȶv̈m̈ᵯǰɏæǽÿẇẏs̃śś̶]+/gm which works great except there is one character I can't include (or that doesn't seem to work as expected when included). The character is (within) the last digit…
0
votes
1 answer

Regex Track1 Magnetic Stripe

How can I create regex rule for name in Track1, following these rules: Allowed Characters would be: ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 .()-$ Not Allowed Characters would be: ^!"&'*+,:;<=>@_[]#%? Required character - only must character /…
CodingMerc
  • 41
  • 5
0
votes
1 answer

How To Capture Positive Lookahead

I am trying to figure out how to capture the positive lookahead group in the following regex: (((Initial commit)|(Merge [^\r\n]+)|(((build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|BREAKING CHANGE)(\(\w+\))?!?: ([\w…
0
votes
3 answers

Python regex where the desired match could be either one or two integers

I have some filenames with information I need toe extract, the information is either one or two numbers in the string. I have code to do either one number or 2 numbers but I cannot get it to work to handle both. I have looked at this Regex match one…
Windy71
  • 851
  • 1
  • 9
  • 30
0
votes
1 answer

After matching a pattern ignore remaing blocks of string (URLs) using REGEX

I am having few URLs as below and I want to check whether they match a regex or…
Jitan Gupta
  • 454
  • 6
  • 18
0
votes
0 answers

Regex: How to Display 4 digits after the "L" (same for after the "C") ? like : L100_C1_"1"_KO,L100_C2_"3260"_KO,etc

Hi Every Regex Expert, I have one Array List al1 like this (line by line): al1 : L1_C1_0, L1_C2_"11229", L1_C2_"CHK_CASHING"_OK, etc... L1_C100_"FR45248624892", L2_C1_0, L2_C2_"11229", L2_C2_"CHK_CASHING"_OK etc... L2_C100_"FR45248624892"_KO,…
0
votes
0 answers

Including and Excluding certain strings regex

(?<=\AL|AL|AK|Alaska|AZ|Arizona|AR|Arkansas|CA|California|CO|Colorado|CT|Connecticut|DE|Delaware|DC|District of…
1 2 3
99
100