title: RegExp for kubernetes pod name
body: <p>I'm using Fluentd as my log shipper in kubernetes, with a <a href="https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter/blob/master/lib/fluent/plugin/filter_kubernetes_metadata.rb#L49" rel="nofollow noreferrer">plugin extracting metadata using a RegExp</a>.
  The plugin currently uses the following regexp -<br>
  <code>'var\.log\.containers\.(?&lt;pod_name&gt;[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)_(?&lt;namespace&gt;[^_]+)_(?&lt;container_name&gt;.+)-(?&lt;docker_id&gt;[a-z0-9]{64})\.log$'</code><br>
  For parsing records structured like so -<br>
  <code>kubernetes.soluto.var.log.containers.my-nice-api-67459fc4f6-g9vk7_namespace-name_container-name-1e1eeab6b6ce257cf6a7a03057159f3b0873dcd5c0cc713cd8c43ed66c5b6b03.log</code></p>
  
  <p>I'm trying to alter the regexp so it will separate the <code>pod_name</code> value into 2 parts -  </p>
  
  <ol>
  <li><p>the pod name derived from the deployment name/explicitly given by the .yaml configuration</p></li>
  <li><p>The hash appended to the pod_name (separated from the pod_name by 2 hyphens)</p></li>
  </ol>
  
  <p>I could've used the hyphen character as a delimiter and be done with it easily, but since the <code>pod_name</code> itself may contain hyphens this is impossible.</p>
  
  <p>I therefore have to find a pattern that will capture a group that will contain the pattern without the last two hyphen delimited parts.</p>
  
  <p>I've constructed <a href="https://regex101.com/r/b3JHIM/1" rel="nofollow noreferrer">this regexp</a> and played around with it, but it does not behave as expected. Would love any help with this.</p>