Home > OS >  Exclude first match from regex subpattern
Exclude first match from regex subpattern

Time:02-02

I'm trying to match pairs of values from a string like 4284{336}1656{595}2961

I want to match 336 and 1656 as one group of two matches, 595 and 2961 as another, and never match the leading 4284.

I'm using ( (?<={) .*? (?=}) )* ([^{}]*)*, but that's matching the 4284. Please note I've added spaces just to make it more readable. My working example is at https://regex101.com/r/P1kef7/1

How can I exclude the first group? Any one of these groups varies in length.

CodePudding user response:

You can match the digits between the curly's and the digits direct after it in 2 capture groups:

{(\d )}(\d )

Regex demo

  •  Tags:  
  • Related