-1

I am currently trying to make use of the java string function someString.replaceAll() to find commonly used words (and, the, by, of, etc) and replace them with " ". Based on the answers to the question at Whitespace Matching Regex - Java, I produced this function call:

data.replaceAll("(?i)\\sthe\\s", " ")

However, it isnt working and I'm really not sure why. Nothing about it looks wrong based on what I've found. Please help me!

Community
  • 1
  • 1
taylorc93
  • 3,676
  • 2
  • 20
  • 34
  • 3
    It isn't working - means? What output are you getting after that replace? – Rohit Jain Jul 02 '13 at 19:20
  • Meaning that it isn't replacing any of the words that I place in the regex with " ". It led me to assume that my regex wasnt matching the word, but I dont know why it isnt, since it looks right to me – taylorc93 Jul 02 '13 at 19:22
  • commonly words without a pattern just use `replace` instead of replaceAll – nachokk Jul 02 '13 at 19:23
  • Can you post complete code? I tried the following and it seems to replace 'The' string with space. For input 'me The rt', the code below prints 'me rt'. String data = "me The rt"; String result = data.replaceAll("(?i)\\sthe\\s", " "); System.out.println(result); – user1573133 Jul 02 '13 at 19:31

1 Answers1

7

Strings are immutable!

data = data.replaceAll("(?i)\\sthe\\s", " ");
arshajii
  • 127,459
  • 24
  • 238
  • 287