LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-26-2004, 10:12 AM   #1
groentebroer
LQ Newbie
 
Registered: Nov 2004
Posts: 1

Rep: Reputation: 0
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
 
Old 11-26-2004, 10:23 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Your reg is fine, just enable it with the -r switch

$ echo "1 + 2 ++ 3 +++++" | sed -r 's/\++/ /g'
 
Old 11-29-2004, 09:15 PM   #3
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
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'
This will match a single '+', followed by zero or more additional '+', and replace them with a space.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expression question gauge73 Linux - General 5 10-28-2005 11:33 AM
Regular expression question gauge73 Linux - General 2 10-28-2005 09:32 AM
regular expression question zero79 Linux - Software 1 07-11-2005 07:03 PM
Regular expression question - John Sloan Linux - Software 1 09-08-2004 12:33 PM
regular expression question Gantrep Linux - Software 2 04-20-2003 04:24 PM


All times are GMT -5. The time now is 01:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration