Help with a regular expression???

James Michael Fultz croooow at gmail.com
Wed Jan 27 18:04:17 UTC 2010


* Ray Parrish <crp at cmc.net> [2010-01-27 09:04 -0800]:
> Amedee Van Gasse (ub) wrote:
[...]
> > The same regex syntax can be used with the bash command sed:
> >
> > sed 's/    ([^ ])/_ \1/g'
[...]
> DescriptionSection=`echo | sed 's/    ([^ ])/_ \1/g'`
> echo "$DescriptionSection"
> 
> And I get the following cryptic error, which tells me nothing. Can you help?
> 
> sed: -e expression #1, char 19: invalid reference \1 on `s' command's RHS

DescriptionSection=`echo | sed 's/    \([^ ]\)/_ \1/g'`

sed uses basic regular expressions (BREs) which does not treat
parentheses specially unless quoted by a backslash.  regex(7) covers the
differences between basic and extended regexes pretty well.  Also, GNU
sed -- which you'll find on Ubuntu and most other Linux distributions --
has an option ('--extended-regexp' or '-r') to enable usage of extended
regular expressions (EREs).




More information about the ubuntu-users mailing list