473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Regex for replacing all consecutive dashes to single dash

Hi,

I want to replace all consecutive (2 or more) dashes into a single
dash.

So text like "hello--world is-cool------ok?"

should become "hello-word is-cool-ok?"

so it doesn't effect anything except replace all consecutive dashes
into a single dash.

What would the regex look like?
Feb 27 '08 #1
2 5161
DotNetNewbie wrote:
I want to replace all consecutive (2 or more) dashes into a single
dash.
See
<URL:http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/6959b1e85a7ea69e/5604494b6830ccfb?lnk=st&q=#5604494b6830ccfb>,
code there is VB.NET but the regular expression obviously is the same
for all .NET languages.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 27 '08 #2
something like: Text = Regex.Replace(Text, "-{2,}", "-") ;

/LM

"DotNetNewbie" <sn***********@yahoo.comwrote in message
news:e3**********************************@60g2000h sy.googlegroups.com...
Hi,

I want to replace all consecutive (2 or more) dashes into a single
dash.

So text like "hello--world is-cool------ok?"

should become "hello-word is-cool-ok?"

so it doesn't effect anything except replace all consecutive dashes
into a single dash.

What would the regex look like?

Feb 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Stephen Poley | last post by:
One disadvantage of using a simple text editor to produce HTML is that it is relatively time-consuming to put in the proper typographical quotation marks and dashes. A round tuit having arrived...
14
by: enrique | last post by:
I'm trying to debug my expression that matches an alphanumeric with any number of dashes (including none), except at the ends and obviously disallowing two or more consecutive dashes. Here it...
3
by: Rico | last post by:
If there are consecutive occurrences of characters from the given delimiter, String.Split() and Regex.Split() produce an empty string as the token that's between such consecutive occurrences. It...
3
by: Craig Buchanan | last post by:
Is there a way to combine these two Replace into a single line? Regex.Replace(Subject, "\&", "&amp;") Regex.Replace(Subject, "\'", "&apos;") Perhaps Regex.Replace(Subject, "{\&|\'}", "{&amp;|&apos;}")...
8
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the...
11
by: proctor | last post by:
hello, i have a regex: rx_test = re.compile('/x()*x/') which is part of this test program: ============ import re
6
by: =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?= | last post by:
Hi, I need to replace double quotes inside the text from the database with " to correctly display my text. I was trying to use Regex to perform such a task: Regex.Replace(text, "", """) to...
5
by: DbZ | last post by:
Hi - i'm new to the regex thing - and trying to learn it to myself - Can someone please explain to me what the following line does - value.replace(/\s+$/g,"") I can kinda figure out its...
0
by: Neil | last post by:
I am having trouble using long dashes (Em dashes) with the Microsoft Rich Textbox 6.0 control. Whenever I paste them in, the control converts them to hyphens. I have found it is the same with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.