regex - extracting text between "[-" and "-]" using grep -


i have text file words/phrases tagged

[-sample text-] 

or

{+sample text+} 

how can use grep extract bracketed words in text?

use grep pcre support

you're describing appears word-diff format. difficult standard grep, easy more powerful regular expression engines pcre.

with pcre (perl-compatible regular expression) library compiled grep, or pcregrep binary, can use types of zero-width assertions in pattern. example, assuming have following file contents:

foo [-sample text 1-] bar {+sample text 2+} baz 

you can correct result with:

$ pcregrep -o '(?<={\+|\[-).*?(?=\+}|-\])' /tmp/foo sample text 1 sample text 2 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -