You do not need a greedy regular expression, but unfortunately sed does not allow this. However, this can be done in perl.
perl -pe 's|__(.*?)__|{{$1}}|g' <myfile
The question mark after the asterisk means that the match is inanimate, so instead of taking the longest match string that he can find, he will take the shortest.
Hope this helps.
If you want to put this in a perl script and not run on the command line, then something like this will do the job:
#! /usr/bin/perl -w use strict;
The use is simple:
./regex myfile whatever{{MATCH_THIS}}whateverwhatever{{AND_THIS}}whateverwhatever
This is Perl, there is a million and one way to do it!
source share