Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex Match all instances of [ab_23] in a string

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

>Solution :

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+\]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading