Solved

Regular expressions

Posted on 2004-09-27
6
287 Views
Last Modified: 2010-04-23
Is it possible in VB.Net to write  a regular expression that will replace any character that appears more than once consecutively with just one of that character?

For example 'sssdftrgggh' -> 'sdftrgh' or 11125644766 -> 1256476

Thanks,

Tommy
0
Comment
Question by:TommyV10
6 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12159707
I don't know about a regular expression but this should do the same

Public Function removedbl(ByVal s As String) As String
        Dim returnstring As String
        Dim x As String = ""
        For y As Integer = 0 To s.Length - 1
            If Not s.Substring(y, 1) = x Then
                returnstring += s.Substring(y, 1)
                x = s.Substring(y, 1)
            End If
        Next
        Return (returnstring)
    End Function
0
 

Expert Comment

by:bradtm
ID: 12161996
Here is a resource of hundreds of already made regexpressions.

http://regexlib.com/DisplayPatterns.aspx
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 12170693
([\w])\1

Bob
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:TommyV10
ID: 12177176
Thanks Bob, that sort of works but it only seems to perfrom the replace if an odd number of characters are encountered.  It will replace 'a' or 'aaa' to 'a' but leaves out 'aa' or 'aaaa'
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12178742
Yeah, I noticed that too.  You could try a While...End While loop, until their are no more matches.

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12183039
([\w])\1+

Bob
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question