This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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
Posts: 22185
38
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
Sheriff
Posts: 22830
119
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
Posts: 22185
38
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!