public static NamingSelector newIpSelector(String regex) {
        if (regex == null) {
            throw new IllegalArgumentException("The parameter 'regex' cannot be null.");
        }
        return new DefaultNamingSelector(instance -> Pattern.matches(regex, instance.getIp()));
    }
@Test
    public void testNewIpSelector() {
        Instance ins1 = new Instance();
        ins1.setIp("172.18.137.120");
        Instance ins2 = new Instance();
        ins2.setIp("172.18.137.121");
        Instance ins3 = new Instance();
        ins3.setIp("172.18.136.111");
        
        NamingContext namingContext = mock(NamingContext.class);
        when(namingContext.getInstances()).thenReturn(Arrays.asList(ins1, ins2, ins3));
        
        NamingSelector ipSelector = NamingSelectorFactory.newIpSelector("^172\\.18\\.137.*");
        NamingResult result = ipSelector.select(namingContext);
        List<Instance> list = result.getResult();
        
        assertEquals(2, list.size());
        assertEquals(ins1.getIp(), list.get(0).getIp());
        assertEquals(ins2.getIp(), list.get(1).getIp());
    }