아래와 같은 문자열들이 있을 때 대문자와 숫자로 조합된 문자만 나오게 정규식을 짜고 싶은데 잘 안되네요
고수님들의 도움 부탁 드립니다.
WITH T AS (SELECT '[폴햄키즈]POLHAMKIDS 오리털롱패딩점퍼 PKX4JP1040[패션플러스]' TXT FROM DUAL UNION ALL
SELECT '[커클랜드] KIRKLAND 콜롬비안 원두커피 Dark Roast-Fine Grind1.36kg' TXT FROM DUAL UNION ALL
SELECT '80NPNALP001BAN_네파성인레터슬리퍼_녹색280' TXT FROM DUAL)
SELECT *
FROM T;
WITH T AS (SELECT '[폴햄키즈]POLHAMKIDS 오리털롱패딩점퍼 PKX4JP1040[패션플러스]' TXT FROM DUAL UNION ALL SELECT '[커클랜드] KIRKLAND 콜롬비안 원두커피 Dark Roast-Fine Grind1.36kg' TXT FROM DUAL UNION ALL SELECT '80NPNALP001BAN_네파성인레터슬리퍼_녹색280' TXT FROM DUAL) SELECT TXT , REGEXP_SUBSTR(TXT, '(([A-Z]+[0-9]+)+|([0-9]+[A-Z]+)+)', 1) RESULT FROM T;
WITH t AS ( SELECT 1 no, '[폴햄키즈]POLHAMKIDS 오리털롱패딩점퍼 PKX4JP1040[패션플러스]' txt FROM dual UNION ALL SELECT 2, '[커클랜드] KIRKLAND 콜롬비안 원두커피 Dark Roast-Fine Grind1.36kg' FROM dual UNION ALL SELECT 3, '80NPNALP001BAN_네파성인레터슬리퍼_녹색280' FROM dual UNION ALL SELECT 4, '80NPNALP001BAN_네파성인레터슬리퍼_GREEN280' FROM dual ) SELECT no, txt, lv, v FROM (-- 단어 단위로 분리 -- SELECT no, txt , lv , REGEXP_SUBSTR(txt, '[[:alnum:]]+', 1, lv) v FROM t , (SELECT LEVEL lv FROM dual CONNECT BY LEVEL <= 99) WHERE lv <= REGEXP_COUNT(txt, '[[:alnum:]]+') ) WHERE REGEXP_LIKE(v, '^[A-Z0-9]+$') -- 대문자 숫자 조합(단, 대문자만, 소문자만도 가능하므로 아래 조건 추가) AND REGEXP_LIKE(v, '[A-Z]') -- 대문자 포함 AND REGEXP_LIKE(v, '[1-9]') -- 숫자 포함 ORDER BY no, lv ;
WITH T AS (SELECT '[폴햄키즈]POLHAMKIDS 오리털롱패딩점퍼 PKX4JP1040[패션플러스]' TXT FROM DUAL UNION ALL SELECT '[커클랜드] KIRKLAND 콜롬비안 원두커피 Dark Roast-Fine Grind1.36kg' TXT FROM DUAL UNION ALL SELECT '9P80NPNALP001BANA_네파성인레터슬리퍼_녹색280' TXT FROM DUAL) SELECT TXT , REGEXP_SUBSTR(TXT, '([A-Z]+[0-9]+[0-9A-Z]*|[0-9]+[A-Z]+[0-9A-Z]*)+', 1) RESULT FROM T;
오오~ 마농님 말씀듣고 다시 수정했습니다.