Regex replace help

Ville Skyttä ville.skytta at iki.fi
Sun Dec 4 10:18:53 UTC 2011


On 12/04/2011 04:00 AM, Miloslav Trmač wrote:
> On Sun, Dec 4, 2011 at 12:07 AM, Richard Shaw <hobbes1069 at gmail.com> wrote:
>> $ echo "const int TIXML_MAJOR_VERSION = 2;" | sed 's/const int
>> TIXML_MAJOR_VERSION = \([0-9]+\).*/\1/'
>> const int TIXML_MAJOR_VERSION = 2;
> 
> By replacing (sed 's/../../') with (sed -n 's/../../p') you can see
> that the regex doesn't match.  The cause is that sed recognizes an
> "\+" operator, not "+" operator.

...and if you want portability, don't use + or \+ with sed at all to
mean "one or more", use \{1,\} instead.


More information about the devel mailing list