public static StringBuilder toHexNibblesOnly(String instr) {

		// Create the return string builder object.
		StringBuilder sb = new StringBuilder();

		// Do some initial formatting of the binary string to separate the bytes for easier
		// reading.
		instr = addSpaceOnByteBoundary(instr, InputMode.BINARY);

		// Now split the binary string on byte boundaries (spaces).
		String[] instrBytes = instr.split(" ");

		// For each byte, convert it to hex.  If there are any masked characters they will
		// be identified by a '.', so we can't show this as hex; just keep as binary and 
		// put in brackets to more easily identify.
		for (String binary : instrBytes) {
			if (binary.contains(".")) {

				// We have at least one masked bit, so we need to do some work.  Split the byte
				// into 2 nibbles and if either nibble has a '.', then we have to treat the entire
				// thing as a wildcard.
				String nibble1 = binary.substring(0, 4);
				String nibble2 = binary.substring(4, 8);
				if (nibble1.contains(".")) {
					nibble1 = ".";
				}
				else {
					int decimal = Integer.parseInt(nibble1, 2);
					nibble1 = Integer.toString(decimal, 16);
				}
				if (nibble2.contains(".")) {
					nibble2 = ".";
				}
				else {
					int decimal = Integer.parseInt(nibble2, 2);
					nibble2 = Integer.toString(decimal, 16);
				}
				sb.append(nibble1).append(nibble2).append(" ");
			}
			else {

				// If we're here, then take the full 8 bits and convert to 
				// hex, making sure that if a single character is the result, we
				// zero-fill to make more readable.
				int decimal = Integer.parseInt(binary, 2);
				String hex = Integer.toString(decimal, 16);

				if (hex.length() == 1) {
					hex = "0" + hex;
				}
				sb.append(hex).append(" ");
			}
		}
		return sb;
	}
Converts the given binary string to hex, but isn't granular beyond the nibble level. 
e.g. If the byte string is '00101...' the trailing '1' will be treated as a wildcard ('0010....').

Note: This is primarily for YARA work, since YARA does not get down to the bit level.

@param instr
@return
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/instructionsearch/util/InstructionSearchUtils.java