• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 913
  • Last Modified:

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

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
mcainc
Asked:
mcainc
  • 2
1 Solution
 
Fernando SotoRetiredCommented:
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
 
mcaincAuthor Commented:
wow, thanks!
0
 
Fernando SotoRetiredCommented:
Not a problem, glad I was able to help.  ;=)
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now