[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
grep --perl-regexp and empty match
From: |
Jori Mantysalo |
Subject: |
grep --perl-regexp and empty match |
Date: |
Thu, 3 Jul 2003 15:17:29 +0300 (EEST) |
I was trying to get "one" and "two" from string "<B>one</B> and
<B>two</B>". Of course this doesn't work:
grep -o -E '<B>.*</B>'
because it match hole string. So, doing it with perl-style regexp:
grep -o -P '<B>.*?</B>'
well, that works. However, if I dont want tags, just whats inside,
grep -o -P '(?<=<B>)(.+?)(?=</B>)'
OK, but a problem:
echo '<B></B> and <B>two</B>' | grep -o -P '(?<=<B>)(.+?)(?=</B>)'
Well, maybe with star:
echo '<B></B> and <B>two</B>' | grep -o -P '(?<=<B>)(.*?)(?=</B>)'
but now I got no output at all. So, is there any way to get an empty
match from grep?
--
Jori Mäntysalo
- grep --perl-regexp and empty match,
Jori Mantysalo <=