What does '\K' mean in this regex?

后端 未结 1 1228
不知归路
不知归路 2020-12-05 02:30

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         


        
1条回答
  •  感动是毒
    2020-12-05 02:54

    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
    

    0 讨论(0)
提交回复
热议问题