I have just bought a book on Regex to try and get my head around it but I'm still really struggling with it. I am trying to create a java regex that will satisfy a string configuration that can;
- Can contain lowercase letters ([a-z])
- Can contain commas (,) but only between words
- Can contain colon (:) but must be separated by words or multiply (*)
- Can contain hyphens (-) but must be separated by words
- Can contain multiply (*) but if used it must be the only character before/between/after the colon
- Cannot contain spaces, 'words' are delimitated by a hyphens (-) or commas (,) or colon (:) or the end of the string
So for example the following would be true:
- foo:bar
- foo-bar:foo
- foo,bar:foo
- foo-bar,foo:bar,foo-bar
- foo:bar:foo,bar
- *:foo
- foo:*
*:*:*
But the following would be false:
- foo :bar
- ,foo:bar
- foo-:bar
- -foo:bar
- foo,:bar-
- foo:bar,
- foo,*:bar
- foo-*:bar
This is what I have so far:
^[a-z-]|*[:?][a-z-]|*[:?][a-z-]|*