I'm trying to extract part of a string using grep with a regular expression. I already tested the regex using regexr and it's working. I'm on macOS.
This is my code:
echo -e '"HI":"Hola!"' | grep -o '(?=[^\"]).+?(?=":")'
If I try to use the -P
option it shows the usage description for grep:
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
I want to get HI
as the output. Do I need to pipe the grep
output or am I missing something else?
Thanks