Search code examples
regexjqaws-cli

How do I get the regex to return more accurately?


I am trying to get the regex right to return one or the other but not both: When I run for example the following:

aws secretsmanager list-secrets | jq -r ".SecretList[] | select(.Name|match(\"example-*\")) | .Name "

it returns

example-secret_key

as well as

examplecompany-secret_key

how can I modify the command to return one and not the other? Thanks


Solution

  • example-* matches strings that contain example followed by zero or more -.

    ^example- matches strings that start with example-.

    jq -r '.SecretList[].Name | select( test( "^example-" ) )'