Solved

Regular expressions

Posted on 2004-09-27
6
282 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now