java - Regular expression to replace words from a list by whitespaces -
I have a list of words list and a string text For example:
For example: you for example: you , is , in and etc
then, to remove them and replace them with a white space is required.
Please, how do I do this?
I think I should go to each item from the list, then check what the text contains. What regular expressions can I use to remove words (to remove)? They can be followed by white spot or ponctuation.
Expected output for this example: "Deadly Jiva, PHP, Oracle."
PS: I can not remove punctuation marks! I am using Java
Try it out:
string text = "blah blah .. .. "; {Text = text.replaceAll ("\\ s" + word + "\\ s", "\\ s") for (string word: wordlist); // To find the word exactly in your text. } Text = text.replaceAll ("\\ s +", "\\ s");
Comments
Post a Comment