static String extractPossibleNumber(String number){
  Matcher m=VALID_START_CHAR_PATTERN.matcher(number);
  if (m.find()) {
    number=number.substring(m.start());
    Matcher trailingCharsMatcher=UNWANTED_END_CHAR_PATTERN.matcher(number);
    if (trailingCharsMatcher.find()) {
      number=number.substring(0,trailingCharsMatcher.start());
      logger.log(Level.FINER,"Stripped trailing characters: " + number);
    }
    Matcher secondNumber=SECOND_NUMBER_START_PATTERN.matcher(number);
    if (secondNumber.find()) {
      number=number.substring(0,secondNumber.start());
    }
    return number;
  }
 else {
    return "";
  }
}

static String extractPossibleNumber ( String number ) { Matcher m = VALID_START_CHAR_PATTERN . matcher ( number ) ; if ( m . find ( ) ) { number = number . substring ( m . start ( ) ) ; Matcher trailingCharsMatcher = UNWANTED_END_CHAR_PATTERN . matcher ( number ) ; if ( trailingCharsMatcher . find ( ) ) { number = number . substring ( 0 , trailingCharsMatcher . start ( ) ) ; logger . log ( Level . FINER , "Stripped trailing characters: " + number ) ; } Matcher secondNumber = SECOND_NUMBER_START_PATTERN . matcher ( number ) ; if ( secondNumber . find ( ) ) { number = number . substring ( 0 , secondNumber . start ( ) ) ; } return number ; } else { return "" ; } }
attempts to extract a possible number from the string passed in . this currently strips all leading characters that cannot be used to start a phone number . characters that can be used to start a phone number are defined in the valid_start_char_pattern . if none of these characters are found in the number passed in , an empty string is returned . this function also attempts to strip off any alternative extensions or endings if two or more are present , such as in the case of : ( 530 ) 583 - 6985 x302 / x2303 . the second extension here makes this actually two phone numbers , ( 530 ) 583 - 6985 x302 and ( 530 ) 583 - 6985 x2303 . we remove the second extension so that the first number is parsed correctly .
