I am in shell and I have this string: 12 BBQ ,45 rofl, 89 lol
12 BBQ ,45 rofl, 89 lol
Using the regexp: \\d+ (?=rofl), I want 45 as a result.
\\d+ (?=rofl)
45
You can do this with GNU grep's perl mode:
echo "12 BBQ ,45 rofl, 89 lol"|grep -P '\d+ (?=rofl)' -o
-P means Perl-style, and -o means match only.
-P
-o