-2

Beginner here and I'm trying to understand this. Can someone please break down the part in between the single quotes and describe what it does?

grep -oP '(?<=\S\/1\.\d.\s)[345]\d+'

Many thanks in advance!

Sparky1
  • 35
  • 5

1 Answers1

0
  • Positive Lookbehind (?<=\S/1.\d.\s) Assert that the Regex below matches
  • \S matches any non-whitespace character (equal to [^\r\n\t\f\v ])
  • \/ matches the character / literally (case sensitive)
  • 1 matches the character 1 literally (case sensitive)
  • \. matches the character . literally (case sensitive)
  • \d matches a digit (equal to [0-9])
  • . matches any character (except for line terminators)
  • \s matches any whitespace character (equal to [\r\n\t\f\v ]) Match a single character present in the list below [345]
  • 345 matches a single character in the list 345 (case sensitive)
  • \d+ matches a digit (equal to [0-9])
  • + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)

Output simply copied from https://regex101.com/r/HfJSNm/1 : very handy to test/share/have automatic explications on regexes.

Gilles Quenot
  • 143,367
  • 32
  • 199
  • 195
  • You do not need to copy/paste regex101 output, the post is a dupe and must be closed. [What does this regex mean](https://stackoverflow.com/questions/22937618), under *Tools: Testers and Explainers*, contains even more tools helping understand a regex pattern. – Wiktor Stribiżew Feb 20 '18 at 21:48