• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to remove special/hidden characters from a string with a regex expression

 
Theodore David Williams
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to remove the special/hidden characters from a string using a regex expression. Is there an easy way to get all escape characters or do I just need to add them all



If I need to add them all what are they?? Is there somewhere I can look to find a list?

Thanks
 
Paul Clapham
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're the person who decided you had to remove special, or hidden, or escape characters. I don't believe that Unicode defines any of those terms. So yes, you're going to have to come up with a definition or a list or something. Was this based on some real-life requirement?
 
Joseph Rose
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like:



should work to remove anything that is not a letter or number, at least the hard ones. Just check the HEX values in an ASCII table to remove them in bulk like the sample here.

Hope this helps.

EDIT: I used the table at http://www.asciitable.com/ and the app at http://gskinner.com/RegExr/ to test this.
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regex has a character class, "\p{Graph}", which defines all visible characters. So, using the negate of that character class, should target all whitespaces, control characters, and other out of range characters.

Henry
 
Paul Clapham
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to guess that Mr. Williams won't want to consider the space character as a special character to be deleted, but I could be wrong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic