sql 正则

SELECT
    NAME
FROM
    g_build
WHERE
    NAME REGEXP '^1|^2'

 

 

 Java

    private static String list2str(List<String> list) {
        StringBuilder sb = new StringBuilder();
        String gap = "^";
        for (String companyId : list) {
            sb.append(gap + companyId + ".*");
            gap = "|^";
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String str = "3012";
        List<String> list = new ArrayList<>();
        list.add("10");
        list.add("20");
        list.add("30");
        list.add("40");

        System.out.println(str.matches(list2str(list)));
    }

 

posted @ 2022-04-15 16:02  1156740846  阅读(46)  评论(0编辑  收藏  举报