0

Recently, I was found a grep expression using -P option.

It's looks like the code below:

grep -o -P '(?<="uuid":")[\w\d=]*(?=")'

and the using example is below:

[root@rhel66 worktmp]# cat zdata2
{"valid":"2016-05-28T","uuid":"3BoZXJlLmxvY2FsZXhwaXJhdGlvbjoxNDY5Njk3NzEzMDAwOjVlY2ExMjg3YTBmMjdmNDk1M2YxZTk3ZmQwZTQ3MmFlOW",:"localdomain.local"}
[root@rhel66 worktmp]#
[root@rhel66 worktmp]# cat zdata2 | grep -o -P '(?<="uuid":")[\w\d=]*(?=")'
3BoZXJlLmxvY2FsZXhwaXJhdGlvbjoxNDY5Njk3NzEzMDAwOjVlY2ExMjg3YTBmMjdmNDk1M2YxZTk3ZmQwZTQ3MmFlOW
[root@rhel66 worktmp]#

I don't understand a few part of this expression.

  1. what is (?<="uuid":") mean? (I don't known ? <= mean..)
  2. What is (?=") mean?

Thank you for any help you can provide.

  • http://www.regular-expressions.info/lookaround.html – anubhava Jul 28 '16 at 11:35
  • [It means right this](https://regex101.com/r/aM8nT9/1) and can be reduced to `(?<="uuid":")[\w=]*(?=")` since `\w` matches the text that `\d` matches. – Wiktor Stribiżew Jul 28 '16 at 11:36
  • "`(?<="uuid":")`" means "preceded by `"uuid":"`", and "`(?=")`" means "followed by `"`". `(?<="uuid":")[\w\d=]*(?=")` matches the same lines as `"uuid":"[\w\d=]*"`; the difference is in what `-o` outputs. – ikegami Jul 28 '16 at 11:57

0 Answers0