[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Regular expressions

Posted on 2004-09-27
6
Medium Priority
?
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1500 total points
ID: 12170693
([\w])\1

Bob
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 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