Solved

VB.NET regular expressions only allow a-Z & replace line breaks w/ space...

Posted on 2008-10-28
3
903 Views
Last Modified: 2010-04-21
I am looking to create a function that will only allow a-z, A-Z, 0-9... it should also replace tabs, carriage returns, /, & multiple spaces with a single space

Example:

Hello. The car is about 30 years old!         Isn't that great?

Oh well, he/she will absolutely LOVE IT!!!!


Would return: "Hello The car is about 30 years old isnt that great Oh well he she will absolutely LOVE IT"


0
Comment
Question by:mcainc
[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
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 22828350
Hi mcainc;

Here is sample code that replaces all characters that are not in the range of a-z, A-Z, or 0-9 and replace with a single space character.

Fernando

Imports System.Text.RegularExpressions
 
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
 
        Dim input As String = "Hello. The car is about 30 years old!         Isn't that great?" & vbCr & vbCr & _
            "Oh well, he/she will absolutely LOVE IT!!!!"
 
        Dim output As String = Regex.Replace(input, "([^a-zA-Z0-9]+)", " ")
 
        MessageBox.Show(output)
 
    End Sub
 
End Class

Open in new window

0
 

Author Closing Comment

by:mcainc
ID: 31511006
wow, thanks!
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 22833522
Not a problem, glad I was able to help.  ;=)
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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