Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

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  :-)
0
Marc_Engrie
Asked:
Marc_Engrie
  • 2
1 Solution
 
ozoCommented:
/^[^#:]*:[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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now