Given the following shell script, would someone be so kind as to explain the grep -Po
regex please?
#!/bin/bash
# Issue the request for a bearer
Since not all regex flavors support lookbehind, Perl introduced the \K
. In general when you have:
a\Kb
When “b” is matched, \K
tells the engine to pretend that the match attempt started at this position.
In your example, you want to pretend that the match attempt started at what appears after the ""access_token":" text.
This example will better demonstrate the \K
usage:
~$ echo 'hello world' | grep -oP 'hello \K(world)'
world
~$ echo 'hello world' | grep -oP 'hello (world)'
hello world