Regular Expression Escape Sequence Nightmare!
-
MStanbrook wrote: I'm having an awful time trying to evaluate what needs to be "escaped", and how many times! if you mean putting the slash next to them, you can just put the at sign @, before the string, and any special characters will be ignored. :)
:suss: Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk
:suss:"All programmers are playwrights and all computers are lousy actors."except the " char, which needs to be escaped with a double quote ala vb
-
MStanbrook wrote: I'm having an awful time trying to evaluate what needs to be "escaped", and how many times! if you mean putting the slash next to them, you can just put the at sign @, before the string, and any special characters will be ignored. :)
:suss: Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk
:suss:"All programmers are playwrights and all computers are lousy actors."Here's what I've tried:
sourceString = "123 ABC X!Y%Z}"
System.Text.RegularExpressions.Regex.Match(sourceString,"^[a-z0-9_]").ToString()
which results in: "1" (why only one character?) I've also tried the suggestion:
System.Text.RegularExpressions.Regex.Match(sourceString,@"`!@$%^*()+=\\|[]{};:<>/?,~").ToString()
Which results in: error: managed EE does not understand expression's syntax Removing the @ gives a result of "" (Empty string). Mike Stanbrook mstanbrook@yahoo.com
-
I've recently been pointed in the direction of RegExps for string replacement. However, being new to both C# and RegExps, and Escape characters are giving me fits! I've got got to remove the following characters from a string (not including the double quotes) "`!@$%^*()+=\|[]{};:<>/?,~" I'm having an awful time trying to evaluate what needs to be "escaped", and how many times!:confused: ugh. Mike Stanbrook mstanbrook@yahoo.com
Hi First for Regex, Eric Gunnerson has a nice tool (although i have no clue how Regex works :)). Look on the GotDotNet.com website under user samples. Secondly, lets solve this problem :)
string badchars = @"`!@$%^*()+=\|[]{};:<>/?,~";
foreach (char bad in badchars) input = input.Replace(bad.ToString(), null );Thats it, Hope it helps :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D
-
Here's what I've tried:
sourceString = "123 ABC X!Y%Z}"
System.Text.RegularExpressions.Regex.Match(sourceString,"^[a-z0-9_]").ToString()
which results in: "1" (why only one character?) I've also tried the suggestion:
System.Text.RegularExpressions.Regex.Match(sourceString,@"`!@$%^*()+=\\|[]{};:<>/?,~").ToString()
Which results in: error: managed EE does not understand expression's syntax Removing the @ gives a result of "" (Empty string). Mike Stanbrook mstanbrook@yahoo.com
im sorry, the ^ was meant to be inside the brackets, do this
string sourceString = "123 ABC X!Y%Z}";
Regex r = new Regex(@"[^a-z0-9]", RegexOptions.IgnoreCase);
MessageBox.Show(r.Replace(sourceString, ""));
:suss: Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk
:suss:"All programmers are playwrights and all computers are lousy actors." -
Hi First for Regex, Eric Gunnerson has a nice tool (although i have no clue how Regex works :)). Look on the GotDotNet.com website under user samples. Secondly, lets solve this problem :)
string badchars = @"`!@$%^*()+=\|[]{};:<>/?,~";
foreach (char bad in badchars) input = input.Replace(bad.ToString(), null );Thats it, Hope it helps :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D
Regex is much better way of doing it, look at my last post above your one to see how it is done with regex. :)
:suss: Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk
:suss:"All programmers are playwrights and all computers are lousy actors." -
im sorry, the ^ was meant to be inside the brackets, do this
string sourceString = "123 ABC X!Y%Z}";
Regex r = new Regex(@"[^a-z0-9]", RegexOptions.IgnoreCase);
MessageBox.Show(r.Replace(sourceString, ""));
:suss: Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk
:suss:"All programmers are playwrights and all computers are lousy actors."Thanx, I like to see snippets :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D
-
Thanx, I like to see snippets :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D
Dont we all :-D
:suss: Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk
:suss:"All programmers are playwrights and all computers are lousy actors." -
Hi First for Regex, Eric Gunnerson has a nice tool (although i have no clue how Regex works :)). Look on the GotDotNet.com website under user samples. Secondly, lets solve this problem :)
string badchars = @"`!@$%^*()+=\|[]{};:<>/?,~";
foreach (char bad in badchars) input = input.Replace(bad.ToString(), null );Thats it, Hope it helps :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D
HAHA!:) That was my original approach!! It was suggested that a "better way" was using RegExps. (My example at that time was stripping "{","-", and "}" from GUIDs. Funny how some things come full circle! (note: I wasn't able to find Eric's tool, but there was a RegEx Workbench that might do the trick). Thanks. Mike Stanbrook mstanbrook@yahoo.com
-
HAHA!:) That was my original approach!! It was suggested that a "better way" was using RegExps. (My example at that time was stripping "{","-", and "}" from GUIDs. Funny how some things come full circle! (note: I wasn't able to find Eric's tool, but there was a RegEx Workbench that might do the trick). Thanks. Mike Stanbrook mstanbrook@yahoo.com
MStanbrook wrote: (note: I wasn't able to find Eric's tool, but there was a RegEx Workbench that might do the trick). I'm a spazz.:eek: The RegEx Workbench *IS* Eric's tool. Mike Stanbrook mstanbrook@yahoo.com
-
MStanbrook wrote: (note: I wasn't able to find Eric's tool, but there was a RegEx Workbench that might do the trick). I'm a spazz.:eek: The RegEx Workbench *IS* Eric's tool. Mike Stanbrook mstanbrook@yahoo.com
Sorry , i was gonna reply but it slipped my mind, glad you made the association :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D