Regular expression with & as separator
java, regex
Solution
Try this way
String data = "&hello&&bye&";
Matcher m = Pattern.compile("&([^&]*)&").matcher(data);
while (m.find())
System.out.println(m.group(1));
output:
hello
bye
Problem
I was given a long text in which I need to find all the text that are embedded in a pair of `&` (For example, in a text `"&hello&&bye&"`, I need to find the words `"hello"` and `"bye"`). I try using the regex `".*&([^&])*&.*"` but it doesn't work, I don't know what's wrong with that. Any help? Thanks