Home > Software design >  Regex Match all instances of [ab_23] in a string
Regex Match all instances of [ab_23] in a string

Time:01-26

I am trying to match all instances of [ab_456] where the numbers can be any digits and any amount in a string.

I have almost got it working with

[[ab_\d \]]*\]

but this is also matching [ddf444] this part of this string and I cant work out why.

As I am trying to match square brackets I am not sure how they are working in my regEx as I was using trial and error to get it working and now have got a bit lost!

CodePudding user response:

So with [] it matches with ANY character inside, you probably want to use () which are for capture groups, but maintain specific order (\[ab_\d \])

or omit () and just have \[ab_\d \]

  • Related