Sorry to bother, I feel permanently lost when it comes to regex...
I have to match a string which occurs in a longer sequence of hex-values. My test-string is this:
BF1301020302000017BF1301030101010300FF6ABF130201010300FFC0BF1303010303030100FF98
Pattern is this:
I tried BF13(\w\w)+?00(\w\w){1}
but it's obviously wrong.
The test-string is supposed to match and output these values:
Thanks, guys!
This one will do the job :
BF13(?:0[123])+00[A-Z0-9]{4}
Explanation
BF13
BF13 literally
(?:...)+
Followed by something (non capturing group) at least one time (+
)
0[123]
a zero followed by 1, 2 or 3
00
Followed by 00
[A-Z0-9]{4}
Followed by uppercase char or a digit 4 times
Sample PHP code Test online
$re = '/BF13(?:0[123])+00[A-Z0-9]{4}/';
$str = 'BF1301020302000017BF1301030101010300FF6ABF130201010300FFC0BF1303010303030100FF98';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $val) {
echo "matched: " . $val[0] . "\n";
}