Reputation: 2336
i'm trying with #(?:[a-fA-F0-9]{2}[,])*(?:[a-fA-F0-9]{2}(?!,)){0,1}#
to match the following lines:
#1C,B4,97,A3,EF,CF,5A,4A# //should match
## //should match
#1C# //should match
#01# //should match
#1C,1C,1C,1C,# //should not match
#1C,# //should not match
#1C # //should not match
# 1C# //should not match
#11C# //should not match
#11C,,1C# //should not match
#1# //should not match
#ZZ# //should not match
but on regex101 it only matches the first line, why? thank you
Upvotes: 1
Views: 30
Reputation: 785376
You may use this regex:
#(?:[a-fA-F0-9]{2}(?:,[a-fA-F0-9]{2})*)?#
RegEx Details:
#
: Match #
(?:
: Start non-capture group
[a-fA-F0-9]{2}
: Match 2 hex characters(?:
: Start 2nd non-capture group
,
: Match a comma)*
: End 2nd non-capture group. *
makes this group repeat 0 or more times)?
: End non-capture group.?
makes this match optional#
: Match #
Upvotes: 1