x Hint: Register, if you want to hide ads.
x Did you like it? Well, then please consider making a donation :)

Remove all non alphanumeric characters from a string except dash & space symbol

Replace this Regex with an empty string + Compiled flag

Tags: #alphanumeric, #characters, #chars, #dash, #remove, #replace, #space, #string. Views: 4649. stackoverflow, 7/12/2015
Link 1: http://www.systemtextregularexpressions.com/r11/remove-all-non-alphanumeric-characters-from-a-string-except-dash-space-symbol
Link 2: http://www.systemtextregularexpressions.com/r11 (short)


Length: 0b, Line: 1, Cursor: 0

RegexOptions

IsMatch=true

Result

I want to remove all special characters from a string. Allowed characters are AZ uppercase or lowercase numbers 09 underscore _ or the dot sign .

Share (without adding to database):

Source code

0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
//.NET Regex.Replace Online Tester: www.systemtextregularexpressions.com

//Namespace
using System.Text.RegularExpressions;

//Regex Pattern
string pattern = @"[^a-zA-Z0-9_. ]+";

//Regex example #1
Regex r = new Regex(@"[^a-zA-Z0-9_. ]+", RegexOptions.Compiled);
string result1 = r.Replace("input text", "replacement text");

//Regex example #2
string result2 = Regex.Replace("input text", @"[^a-zA-Z0-9_. ]+", "replacement text", RegexOptions.Compiled);
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
'.NET Regex.Replace Online Tester: www.systemtextregularexpressions.com

'Namespace
Imports System.Text.RegularExpressions

'Regex Pattern
Dim pattern As String = "[^a-zA-Z0-9_. ]+"

'Regex example #1
Dim r As Regex = New Regex("[^a-zA-Z0-9_. ]+", RegexOptions.Compiled)
Dim result1 As String = r.Replace("input text", "replacement text")

'Regex example #2
Dim result2 As String = Regex.Replace("input text", "[^a-zA-Z0-9_. ]+", "replacement text", RegexOptions.Compiled)