We help IT Professionals succeed at work.

Regex problem

Marc_Engrie
Marc_Engrie asked
on
Medium Priority
273 Views
Last Modified: 2012-03-15
Hello,

I have a string of multiple 'blocks' of colors in Hex notation. The number of blocks can vary from 1 to 9. each is separated with one or more spaces.

eg: string with 2 block  BLCK1:#222222 BLCK2:#333333
string with 4 blocks  BLCK1:#123456 TEXT:#654321 LINE:#334455 FONT:#214365

I want to validate such a string line against some basic rule:
.*?:#[0-9a-f]{6}.

but how can I do this for every block in the string within the regex?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
What do you mean by "validate"? Your pattern should match each occurrence.
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
/^[^#]*#[0-9a-f]{6}( +[^#]*#[0-9a-f]{6})*$/

Author

Commented:
working

Thx!

Author

Commented:
Additional about this:

what needs to change in the regex in order to detect/allow besides

BLCKX#123456   also   BLCKX#12345678

but not  BLCK1:#1234567

What is the difference  between   .*?  (lazy)   and  [^#]

Explore More ContentExplore courses, solutions, and other research materials related to this topic.