Validating varying substrings

Hello,

I am not that experienced in regex and I struggle with the following

$string = 'DEFAULT:1:  TITLE:5    AXIS:6:     UNIT:13:     LEGEND:21:   WATERMARK:1: ';
print "yes\n" if ($string =~ /^[^#]*:[0-9]+:[^#]*( +[^#]*:[0-9]+:[^#]*)*$/i)

Open in new window

This code should accept TEXT:9:TEXT  or  TEXT:99:  or  TEXT:2:"TEXT"   but should not accept
TEXT:9 or   TEXT:   or  TEXT.

The regex I have here does accept TEXT:5  which it shouldn't  :-)
Marc_EngrieAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
/^[^#:]*:[0-9]+:[^#:]*( +[^#:]*:[0-9]+:[^#:]*)*$/
0
 
Marc_EngrieAuthor Commented:
Yes !!!

However I do not fully understand [^#:]*:

Can you enlighten me on this so I learn something today ;-)  

Thx a lot
0
 
wilcoxonCommented:
[^#:]* says to match 0 or more characters that are not # or :
0
 
Marc_EngrieAuthor Commented:
Understood and learned !

Thx :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.