Regex 101 Answer I10 – Extract repeating hex blocks from a string

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

Given the string:


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


You can match the hex digits with:


Like our last example, you can call Match() multiple time, use Matches(), or do it in a single call with:


Comments (4)

  1. Maurits says:

    Actually your last pattern misses the final hex number… unless you do something like

    r.Match(str + "&")





    (…or does that not work?  it seems suspicious to have two capturing clauses with the same name…)

  2. Maurits says:

    Er, the + is superfluous on my last regex.  Should be:


    or better

    H'(?<Values>[0-9a-fA-F]{4}) # first hex number


    __ & # second and further hex numbers are separated with &

    __ H'(?<Values>[0-9a-fA-F]{4}) # second and further hex number

    )* # further hex numbers are optional

  3. kbiel says: