<p>I'm trying to retrieve pods using a JSONPATH query which matches the name with a certain pattern matching as specified below and I get the error as shown. Any reason what would be the reason for the failure.</p>
<pre><code>kubectl get po -n sdfd -o jsonpath='{.items[?(@.metadata.generateName =~ /abc.*?/i)].status.podIP}'
error: error parsing jsonpath {.items[?(@.metadata.generateName =~ /abc.*?/i)].status.podIP}, unrecognized character in action: U+007E '~'
</code></pre>
<p>Please find the kubectl cli version as shown below :-</p>
<pre><code>kubectl version                                                  
Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;19&quot;, GitVersion:&quot;v1.19.0&quot;, GitCommit:&quot;e19964183377d0ec2052d1f1fa930c4d7575bd50&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2020-08-26T21:54:15Z&quot;, GoVersion:&quot;go1.15&quot;, Compiler:&quot;gc&quot;, Platform:&quot;darwin/amd64&quot;}
Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;20&quot;, GitVersion:&quot;v1.20.9&quot;, GitCommit:&quot;454b5b515582f8ac8419435dc9c230fc97fb844b&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-11-01T19:59:05Z&quot;, GoVersion:&quot;go1.15.14&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
</code></pre>

Avi
<p>According to the <a href="https://kubernetes.io/docs/reference/kubectl/jsonpath/" rel="nofollow noreferrer">documentation</a>:</p>
<blockquote>
<p>JSONPath regular expressions are not supported. If you want to match using regular expressions, you can use a tool such as <strong>jq</strong>.</p>
</blockquote>
<p>Run the following command to achieve the desired result:</p>
<pre><code>kubectl get pods -o json | jq -r '.items[] | select(.metadata.name | test(&quot;test-&quot;)).spec.containers[].image'
</code></pre>
<p>Refer to this Github <a href="https://github.com/kubernetes/kubernetes/issues/61406" rel="nofollow noreferrer">issue</a> and  <a href="https://stackoverflow.com/questions/36211618/how-to-parse-json-format-output-of-kubectl-get-pods-using-jsonpath">stackpost</a> for more information.</p>
