I have a string like this and I would like to eliminate all the tokens that contain a number:
String[] s="In the 1980s".split(" ");
Is there a way to remove the tokens that contain numbers - in this case 1980s
, but also, for example 784th
or s787
?
Use a
\w*\d\w*
regex matcher for that. It will match all words with at least one digit in them. Although I generally despise regexes, they are particularily well suited for your problem.See Java lib docs for Pattern/Matcher (RegEx) for more reference how to work with regexes in general.
Test code: http://ideone.com/LrHDsT