![]() |
Regular expression question.
Hi,
I would like to have a *unknown* number of '+' signs with one space. So "+" should be " " also "+++" should be " " and "++++++" should be " ". I came up with the following: $ echo "1 + 2 ++ 3 +++++" | sed -e 's/\++/ /g' But this replaces all double plus signs ("++") with a space. So "+" is not replaced and "++++" is replaced with to spaces (" ") I have tried groups and brackets and everything I could come up with. Has somebody else any idea or solution? Thanx, Gijs |
Your reg is fine, just enable it with the -r switch
$ echo "1 + 2 ++ 3 +++++" | sed -r 's/\++/ /g' |
Yeah, the use of '+' (meaning one or more) in an regex is considered an extended notation. To do the same thing without needing extended notation, try:
Code:
echo "1 + 2 +++ 3 ++++++" | sed -e 's/++*/ /g' |
| All times are GMT -5. The time now is 10:20 PM. |