Darryl Burke wrote:What's wrong with sentence.replaceAll("(?:\\b)[a-z]*(?:\\b)", "")? And if the double spaces left behind are an issue, that could be chained to .replace(" ", " ").
That regular expression does not take into account that the sentence could consist of characters other than a-z, A-Z and spaces.
Ah, I see.
Stephan van Hulst wrote:Also, the second replace would have to be performed multiple times until there are no more changes.
Um, no.
String#replace(CharSequence target, CharSequence replacement) wrote:Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.
luck, db
There are no new questions, but there may be new answers.
Yes, but if you have three spaces in a row, it will replace the first two with a single space, but the two spaces that are left over will not be replaced, because the matcher has moved past the first one (which was a replacement).
Stephan van Hulst wrote:Carey, that suffers from the same problem. If the replacement results in multiple spaces in a row, they won't be recursively replaced.
The "\\s" means any white space character. The "+" says one or more. So you have a replacement pattern of one or more adjacent spaces to be replaced by a single space.
I haven't been following this thread carefully; once it go onto the second page it started to get long‑winded. But a long time ago somebody showed how to extract upper case letters from the String with a Stream. So why do you insist on wanting a regex?
Carey Brown wrote:
The "\\s" means any white space character. The "+" says one or more. So you have a replacement pattern of one or more adjacent spaces to be replaced by a single space.
Yes, but it won't replace the replacements that result in multiple spaces in a row. Nevermind, it was a long weekend
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad: