Source:
<code>public IncomingPhoneNumber checkIncomingPhoneNumberRegexMatch ( String selector, String inBoundPhoneNumber){ final SqlSession session = sessions.openSession(); String phoneRegexPattern = null; try { List<IncomingPhoneNumber> listPhones = getAllIncomingPhoneNumbers(); <START> for (IncomingPhoneNumber listPhone : listPhones){ <END> if (listPhone.getPhoneNumber().startsWith("+")){ phoneRegexPattern = listPhone.getPhoneNumber().replace("+", "/+"); }else if (listPhone.getPhoneNumber().startsWith("*")){ phoneRegexPattern = listPhone.getPhoneNumber().replace("*", "/*"); }else{ phoneRegexPattern = listPhone.getPhoneNumber(); } Pattern p = Pattern.compile(phoneRegexPattern); Matcher m = p.matcher(inBoundPhoneNumber); if (m.find()) { final Map<String, Object> resultRestcommRegexHostedNumber = session.selectOne(namespace + selector, phoneRegexPattern); if (resultRestcommRegexHostedNumber != null) { return toIncomingPhoneNumber(resultRestcommRegexHostedNumber); }else{ logger.error("Error, Regex check returns a null value " ); } } } logger.warn("No matching phone number found, make sure your Restcomm Regex phone number is correctly defined"); }finally { session.close(); } return null; }</code><technical_language>@croufay I get reason stored numbers build Regex pattern. elaborate? This efficient way</technical_language>

Target:
public IncomingPhoneNumber checkIncomingPhoneNumberRegexMatch ( String selector, String inBoundPhoneNumber){ final SqlSession session = sessions.openSession(); String phoneRegexPattern = null; try { List<IncomingPhoneNumber> listPhones = getIncomingPhoneNumbersRegex(); if (logger.isInfoEnabled()) { String msg = String.format("Found %d Regex IncomingPhone numbers",listPhones.size()); logger.info(msg); } for (IncomingPhoneNumber listPhone : listPhones){ if (listPhone.getPhoneNumber().startsWith("+")){ phoneRegexPattern = listPhone.getPhoneNumber().replace("+", "/+"); }else if (listPhone.getPhoneNumber().startsWith("*")){ phoneRegexPattern = listPhone.getPhoneNumber().replace("*", "/*"); }else{ phoneRegexPattern = listPhone.getPhoneNumber(); } Pattern p = Pattern.compile(phoneRegexPattern); Matcher m = p.matcher(inBoundPhoneNumber); if (m.find()) { final Map<String, Object> resultRestcommRegexHostedNumber = session.selectOne(namespace + selector, phoneRegexPattern); if (resultRestcommRegexHostedNumber != null) { if (logger.isInfoEnabled()) { String msg = String.format("Pattern \"%s\" matched the phone number \"%s\"",phoneRegexPattern, inBoundPhoneNumber); logger.info(msg); } return toIncomingPhoneNumber(resultRestcommRegexHostedNumber); } else{ if (logger.isInfoEnabled()) { String msg = String.format("Error, Regex \"%s\" cannot be matched for phone number \"%s\"", phoneRegexPattern, inBoundPhoneNumber); logger.info(msg); } } } else { if (logger.isInfoEnabled()) { String msg = String.format("Error, Regex \"%s\" cannot be matched for phone number \"%s\"", phoneRegexPattern, inBoundPhoneNumber); logger.info(msg); } } } logger.info("No matching phone number found, make sure your Restcomm Regex phone number is correctly defined"); } catch (Exception e) { if (logger.isDebugEnabled()) { String msg = String.format("Exception while trying to match for a REGEX incoming phone number"); logger.debug(msg); } } finally { session.close(); } return null; }