Windows Phone Developers

Sunday, April 27, 2008

Regular Expressions in Dot Net (.NET)

Finding Duplicate Words in a String using .NET Regular Expressions

Regular Expressions (REGEX) does wonders in programming. Here is a simple Regex code that identifies duplicate words like 'the the', 'something something' etc. Probably copyeditors can use this code to do the work that Microsoft Spell check does


Sub Regex_Checker_Duplicate_Words()

Dim oRegex As Regex

Dim sPattern As String

Dim oMatches As Match

Dim sText As String

sText = " the the category catastropic cat cat and rat b b "

sPattern = "\b([a-zA-Z]+)\s+\1"

oRegex = New Regex(sPattern)

oMatches = oRegex.Match(sText, sPattern)

While oMatches.Success

MsgBox(oMatches.Groups(0).Value.ToString)

oMatches = oMatches.NextMatch

End While

End Sub

Returns a new Match with the results for the next match, starting at the position at which the last match ended (at the character beyond the last matched character).

See Also
Extract Ref Links From WebPage using VB.Net Regular Expressions
Remove HTML Tags from String using .NET Regular Expressions
VB.NET Regular Expression to Check URL
VB.NET Regular Expression to Check Email Addresses
VB.NET Regular Expression to Check MAC Address
Regular Expression to Check Zip Code
Validate eMail Addresses using VB.NET Function
Regular Expressions in Dot Net (.NET)

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005