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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With