Solved

Regex problem

Posted on 2012-03-14
4
245 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?
0
Comment
Question by:Marc_Engrie
  • 2
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37721929
What do you mean by "validate"? Your pattern should match each occurrence.
0
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 37721933
/^[^#]*#[0-9a-f]{6}( +[^#]*#[0-9a-f]{6})*$/
0
 

Author Comment

by:Marc_Engrie
ID: 37722030
working

Thx!
0
 

Author Comment

by:Marc_Engrie
ID: 37724517
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  [^#]
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question