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");

```
You have not very clear use case, but my assumptions with code example:

1. omit all symbols with *replaceAll* function
2. omit just first symbol with *substring* function

public class TestRegex {

```
public static void main(String[] args) {

    String omitInStart = "#user";
    String omitInMiddle = "#user";
    String omitInEnd = "#user";
    String omitFewSymbols = "#us#er";

    List<String> listForOmit = Arrays.asList(omitInStart, omitInMiddle, omitInEnd, omitFewSymbols);
    listForOmit.forEach(e -> System.out.println(omitWithReplace(e)));

    listForOmit.forEach(e -> System.out.println(omitFirstSymbol(e)));

}

private static String omitFirstSymbol(String stringForOmit) {
    return stringForOmit.substring(1);
}

private static String omitWithReplace(String stringForOmit) {
    String symbolForOmit = "#";
    return stringForOmit.replaceAll(symbolForOmit, "");
}

```

}