How to extract a value from a string using regex and a shell?

前端 未结 7 1003
Happy的楠姐
Happy的楠姐 2020-12-13 06:11

I am in shell and I have this string: 12 BBQ ,45 rofl, 89 lol

Using the regexp: \\d+ (?=rofl), I want 45 as a result.

7条回答
  •  别那么骄傲
    2020-12-13 06:44

    you can use the shell(bash for example)

    $ string="12 BBQ ,45 rofl, 89 lol"
    $ echo ${string% rofl*}
    12 BBQ ,45
    $ string=${string% rofl*}
    $ echo ${string##*,}
    45
    

提交回复
热议问题