public static long stringToBytes(String formattedString) {
    if (formattedString == null) {
      return 0L;
    }

    Matcher matcher = REGEX_MATCHER.matcher(formattedString.replace(",",""));
    if (!matcher.matches()) {
      throw new IllegalArgumentException(
          "The formatted string [" + formattedString + "] does not match with the regex /" + REGEX_MATCHER.toString()
              + "/");
    }
    if (matcher.groupCount() != 1 && matcher.groupCount() != 2) {
      throw new IllegalArgumentException();
    }

    double numPart = Double.parseDouble(matcher.group(1));
    if (numPart < 0) {
      throw new IllegalArgumentException("The number part of the memory cannot be less than zero: [" + numPart + "].");
    }
    String unitPart = matcher.groupCount() == 2 ? matcher.group(2).toUpperCase() : "";
    if (!unitPart.endsWith("B")) {
      unitPart += "B";
    }
    for (int i = 0; i < UNITS.length; i++) {
      if (unitPart.equals(UNITS[i].getName())) {
        return (long) (numPart * UNITS[i].getBytes());
      }
    }
    throw new IllegalArgumentException("The formatted string [" + formattedString + "] 's unit part [" + unitPart
        + "] does not match any unit. The supported units are (case-insensitive, and also the 'B' is ignorable): ["
        + StringUtils.join(UNITS) + "].");
  }
Convert a formatted string into a long value in bytes.
This method handles

@param formattedString The string to convert
@return The bytes value
app/com/linkedin/drelephant/util/MemoryFormatUtils.java