I'm struggling with a simple regex, for which I can't seem to get right.
I have some text like so:
This comment is great **[@madeUpUser1](/madeUpUser1)** You said something similar did you mate? **[@madeUpUser2](/madeUpUser2)**
What I would like to end up with is an array list containing the usernames inbetween the parentheses i.e.:
0.madeUpUser1
1.madeUpUser2
And here is the code I have so far:
List<String> matches = Pattern.compile("\\((.+?)\\)")
.matcher("This comment is great **[@madeUpUser1](/madeUpUser1)** You said something similar did you mate? **[@madeUpUser2](/madeUpUser2)**")
.results()
.map(MatchResult::group)
.collect(Collectors.toList());
However what I'm getting back is this:
0."(/madeUpUser1)"
1."(/madeUpUser2)"
Again, where I want:
0.madeUpUser1
1.madeUpUser2
i.e. without the parentheses and without the forwardslash
Can anyone shed any light on what I'm doing wrong with my regex please?
(?<=\(\/)[^)]+(?=\)).