Question: I want to replace a word starting with # in a string which contains set of words with the same word (# omitted)

example

"word1 word2 **#user**" should be replaced with "word1 word2 **user**"

Can someone help me?

Answer: 
You can use regex. Lets start with

```
yourText = yourText.replaceAll("#(\\S+)", "$1");

```

in regex:

* `\S` represents any non-whitespace characters
* `+` represents *one or more*
* `\S+` represents one or more non-whitespace characters
* `(\S+)` -parenthesis create group containing one or more non-whitespace characters, this group will be indexed as `1`

in replacement

* `$1` in replacement allows us to use content of group 1.

In other words it will try to find `#non-whitespaces` (which and replace it with `non-whitespaces` part.

But this solution doesn't require `#` to be start of word. To do this we could check if before `#` there is 

* whitespace space `\s`,
* or start of the string `^`.

To test if something is before our element without actually including it in our match we can use look-behind `(?<=...)`.

So our final solution can look like

```
yourText = yourText.replaceAll("(?<=^|\\s)#(\\S+)", "$1");

```
yes, [String.replaceAll()](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace(char,%20char))

```
String foo = "#user"
foo = foo.replaceAll("#", "");

```