I am trying to construct a regular expression with the following requirements
- Pattern should start with letters
a-z - Can have any character from character class
[\w:-]. - Can have any number of underscores
_but only if there is a:somewhere before it in the pattern.
Some examples of valid patters
hello123
hello:123
hello-hello
hello:123-hello_345 # Valid pattern as there is a : in the pattern before _
hello-1:hell_world_123
Invalid patterns
hello_123
hello-123_world
hello_123:world
I have tried using the lookaheads but for some reason it does not work, below is the pattern i came up with
^[a-z]+[a-z0-9:-]*(?<=:)[_]*\w* - the issue with this pattern is that it stops matching the entire pattern if there is no : anywhere in the string, so it kind of makes the : a required pattern.
I only want to check the existence of : if there is _ anywhere in the string before :.
