wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Removing Alpha Characters from a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Removing Alpha Characters from a String" Watch "Removing Alpha Characters from a String" New topic
Author

Removing Alpha Characters from a String

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1462
    
    1
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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}+","");


[Jess in Action][AskingGoodQuestions]
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
Actually, it's "\\p{L}", but with single-letter category names you can drop the braces:
[ July 21, 2008: Message edited by: Alan Moore ]
 
GeeCON Prague 2014
 
subject: Removing Alpha Characters from a String