I have the following text in a file called n8n-deployment:
...
image: busybox:1.36
image: docker.io/n8nio/n8n:2.13.4
imagePullPolicy: IfNotPresent
...
And I want to use Regex search and match the version of n8n, in this case 2.13.4 should be output.
Here’s how this can be done using Ripgrep (rg) command.
➜ rg -N -o -P 'image.*n8n:\K.*$' n8n-deployment.yaml
2.13.4
Another way to do this is:
➜ rg -oN 'image.*n8n:(.*)' -r '$1' n8n-deployment.yaml
2.13.4
Or, with grep:
➜ grep -o -P 'image.*n8n:\K.*$' n8n-deployment.yaml
2.13.4
Explanation of flags:
-N,--no-line-number: Suppress line numbers.-o,--only-matching: Prints only the matched part of the line, not the entire line.-P,--pcre2: Enables Perl-Compatible Regular Expressions, allowing advanced features like\K.-r,--replace: Replaces the match with the specified string, often used with capturing groups.