Skip to content

Commit d1a9cf8

Browse files
authored
Merge pull request #23141 from webmutation/jsonpath-regex-nosupport
Jsonpath regex nosupport
2 parents 9e6ad50 + 691ca62 commit d1a9cf8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

content/en/docs/reference/kubectl/jsonpath.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,16 @@ kubectl get pods -o=jsonpath="{range .items[*]}{.metadata.name}{\"\t\"}{.status.
9898
```
9999
{{< /note >}}
100100

101+
{{< note >}}
102+
103+
JSONPath regular expressions are not supported. If you want to match using regular expressions, you can use a tool such as `jq`.
104+
105+
```shell
106+
# kubectl does not support regular expressions for JSONpath output
107+
# The following command does not work
108+
kubectl get pods -o jsonpath='{.items[?(@.metadata.name=~/^test$/)].metadata.name}'
101109

110+
# The following command achieves the desired result
111+
kubectl get pods -o json | jq -r '.items[] | select(.metadata.name | test("test-")).spec.containers[].image'
112+
```
113+
{{< /note >}}

0 commit comments

Comments
 (0)