Question: I have a long string let's say

```
I like this #computer and I want to buy it from #XXXMall.

```

I know the regular expression pattern is 

```
Pattern tagMatcher = Pattern.compile("[#]+[A-Za-z0-9-_]+\\b");

```

Now i want to get all the hashtags in an array. How can i use this expression to get array of all hash tags from string something like 

```
ArrayList hashtags = getArray(pattern, str)

```

Answer: 
You can write like?

```
private static List<String> getArray(Pattern tagMatcher, String str) {
    Matcher m = tagMatcher.matcher(str);
    List<String> l = new ArrayList<String>();
    while(m.find()) {
        String s = m.group(); //will give you "#computer"
        s = s.substring(1); // will give you just "computer"
        l.add(s);
    }
    return l;
}

```

Also you can use `\\w-` instead of `A-Za-z0-9-_` making the regex `[#]+[\\w]+\\b`
You can use :

```
String val="I like this #computer and I want to buy it from #XXXMall.";
String REGEX = "(?<=#)[A-Za-z0-9-_]+";
List<String> list = new ArrayList<String>();
Pattern pattern = Pattern.compile(REGEX);
Matcher matcher = pattern.matcher(val);
while(matcher.find()){
    list.add(matcher.group());
}

```

`(?<=#)` **Positive Lookbehind** - Assert that the character `#` literally be matched.