/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.regex.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String str = "#1\n#12\n#123\n#1234\n#5069\n#316&\n#316.\n#316;\nand not matches (leading zeros) and numbers that end with ] or [ or are between ().\n\n#0155\n#0000155\n#1123]\n#1123[\n(#1125)";
		String rx = "#[1-9]\\d*(?![\\[\\])])\\b[&.;]?";
		Pattern ptrn = Pattern.compile(rx);
        Matcher m = ptrn.matcher(str);
        while (m.find()) {
            System.out.println(m.group(0));
        }
	}
}