Solved

Regex problem

Posted on 2012-03-14
4
239 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 74

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now