regex - Regular expression to remove everything but words. java -
this code doesn't seem doing right job. removes spaces between words!
input = scan.nextline().replaceall("[^a-za-z0-9]", "");
i want remove spaces , numbers or abbreviations string, except words , character: '
.
for example:
input: 34 4ff$#@d 1 233 r # o'clock 329riewio23
returns: one o'clock
public static string filter(string input) { return input.replaceall("[^a-za-z0-9' ]", "").replaceall(" +", " "); }
the first replace replaces characters except alphabetic characters, single-quote, , spaces. second replace replaces instances of 1 or more spaces, single space.
Comments
Post a Comment