# Regex 101 Exercise I10 – Extract repeating hex blocks from a string

Regex 101 Exercise I10 - Extract repeating hex blocks from a string

Given the string:

PCORR:BLOCK=V5CCH,IA=H'22EF&H'2354&H'4BD4&H'4C4B&H'4D52&H'4DC9;

Extract all the hex numbers in the form “H’xxxx”

1. Josh Krause says:

I am not sure what the meaning is of this post, but am I allowed to post my solution? Or are u going to explain the solution later on regardless of comments? Because I am not really sure what the general idea is of your excersizes. Don’t get me wrong here, I love Regex, I like puzzles like this! 🙂

2. JoshK says:

In any case feel free to delete my submission if it’s not submissable.

(?<HexNumbers>H’w{4})

I always create my Regex in C# with RegexOptions.ExplicitCapture included, so that’s why I included the named group idenitifier.

3. Maurits says:

(H'[0-9A-Fa-f]+)

or

(H'[0-9A-Fa-f]{4})

depending on whether hex numbers are *specified* to have four digits (hexits) or whether they all *just happened* to have four digits in the sample string

I’ve never seen H’ used as a hex indicator before… I have seen 0x, though.  Here’s a version that looks for that:

(0x[0-9A-Fa-f]+)

4. kbiel says:

I was also slightly confused by the title of the post.  My definition of repeating and your differ apparently.  In any case, I propose a solution to your title question –

Given: PCORR:BLOCK=V5CCH,IA=H’22EF&H’2354&H’4BD4&H’4C4B&H’4D52&H’4C4B&H’4DC9&H’2354;

Regex: (?<Hex>H'[a-fA-F0-9]{4})(?=.*?k<Hex>)

That will find repeating blocks (i.e. blocks that are exactly the same; in the example case H’2354 and H’4C4B).

5. Regex 101 Exercise I10 – Extract repeating hex blocks from a stringGiven the string:

PCORR:BLOCK=V5CCH,IA=H’22EF&amp;amp;H’2354&amp;amp;H’4BD4&amp;amp;H’4C4B&amp;amp;H’4D52&amp;amp;H’4DC9;…