It looks like the new version of OSX no longer supports grep -P and as such has made some of my scripts stop working.
var1=`grep -o -P '(?<=<st:italic>).*(?=</italic>)' file.txt`
I need to capture the grep to a variable and I need to use the zero width assertions. as well as \K
var2=`grep -P -o '(property:)\K.*\d+(?=end)' file.txt`
Any alternatives would be greatly appreciated.
use the perl one-liner regex by passing the find output with a pipe. I used lookbehind (get src links in html) and lookahead for " and passed the output of curl (html) to it.
Equivalent of the accepted answer, but without the requirement of the -P switch, which was not present on both machines I had available.
If you want to do the minimal amount of work, change
to
and change
to
So you get:
In your specific case, you can achieve simpler code with extra work.
use perl;
If you need more
grep
options (I see you would like-o
at least) there are variouspgrep
implementations floating around the net, many of them in Perl.If "almost Perl" is good enough, PCRE ships with
pcregrep
.This one worked for me: