Regular expression and repeating character classes in perl

I am trying to write a regular expression that can extract (possibly several) strings of four hexadecimal numbers / letters.

I could do something like this:  /^[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]/

but is there a better way?

The repeat statement seems to be:

a {n} Matches 'a' repeated exactly n times.

a {n,} Matches 'a' repeated n or more times.

a {n, m} Corresponds to 'a' repeated between n and m times inclusive.

Will work, but the following regex does not work:

/^[A-Fa-f0-9]{4}+/

I am trying to match strings, for example:

AA00

AA00FFAA

0011FFAA0022

etc. Each line will be on its own line.

Thank!

+5
source share
2 answers

:

/^(?:[A-Fa-f0-9]{4})+$/
+8

regex; .. {4} 4 , + , . +, :

/^[A-Fa-f0-9]{4}/
+1

All Articles