I am trying to create a regex which matches a key value pair unless it has a hyphen in the beginning. This regex will detect the attribute set from a yaml file. Here is a sample yaml file content
containers:
- name: api-php-container
image: us-west-2.amazonaws.com/abcd:45
ports:
- containerPort: 80
- containerPort: 443
volumeMounts:
mountPath: "/etc/keys/ssl"
- name: certs
The regex should match all lines which are like key:value pairs unless it has an hyphen in the beginning. For example, it will match the following lines:
image: us-west-2.amazonaws.com/abcd:45
mountPath: "/etc/keys/ssl"
Here is the regex I wrote:
^(\s*\-\s*)([\w0-9_\-\.]+)\s*:\s*([\w0-9_\-\.\/]+)\s*$
But this detects the lines which starts with the hyphen.
Then I tried using negative lookahead, but then it stopped matching the whole thing altogether. Here that regex:
^(?!(\s*\-\s))([\w0-9_\-\.]+)\s*:\s*([\w0-9_\-\.\/]+)\s*$
How do I make it detect like I want it?