[Solved] Preg_match for a string key


The regex would be this:

/^[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}$/

Regex explanation:

Start regex expression

/^

Capital A-Z and Numerical 0-9

[A-Z0-9]

5 long exactly

{5}

Dash between sets

End expression

$/

<?php

        $reg = '/^[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}$/';

        $string = 'YTMG3-N6DKC-DKB77-7M9GH-8HVX7';

        preg_match($reg, $string, $matches, PREG_OFFSET_CAPTURE);
        print_r($matches);
     ?>

7

solved Preg_match for a string key