Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Removing Alpha Characters from a String

 
Steve Dyke
Ranch Hand
Posts: 1622
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need the best practice for striping alpha characters a string. Example: 849650-7BLANK

I have this but it will not work

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That first argument is supposed to be a regular expression. A well-formed regular expression representing a sequence of one or more alphabetic characters would be "\{L}+" (this matches all Unicode letters.) With the proper escaping, this looks like

pnstring = pnstring.replaceAll("\\{L}+","");
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, it's "\\p{L}", but with single-letter category names you can drop the braces:
[ July 21, 2008: Message edited by: Alan Moore ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic