正则表达式
ASCII码表 create table ascii_tab(n number(5),s varchar2(4));
将表中的s字段是数字(digit)的提取出来 SQL> select * from ascii_tab where regexp_like(s,'[[:digit:]]'); N S ------ ---- 48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 56 8 57 9*select * from ascii_tab where regexp_like(s,'[[:alpha:]]'); ---alpha字母 select * from ascii_tab where regexp_like(s,'[[:lower:]]'); ---小写字母 ---[A-Za-z0-9] [:punct:] ---标点。[][!"#$%&'()*+,./:;<=>?@^_`{|}~-] [:space:] ---[ tnvfr] ,空白字符
== select * from ascii_tab where regexp_like(s,'[^[:digit:]]'); ----取出所有非数字的字符
正则表达式的应用: 验证格式:电话号码、电子邮箱、IP地址、网址
查找替换: 格式化 1、将IPV4的地址每段都格式化为三位数的,不够的前面补0 2、将字符串str逐字符重复4次,例如'abc'变为'aaaabbbbcccc' regexp_replace(str,'(.)','1111') 3、剔除str中除了逗号和数字之外的字符 regexp_replace(str,'[^[:digit:],]')
提取 1、从str中提取第一个单词(只有字母组成的才算单词) regexp_substr(str,'([[:alpha:]]+)') ---默认从左边第一个位置提取第一个单词
2、将可能是日期的字符串提取出来(yyyy-mm-dd格式)
3、网页源文件的片段已存入str中,从中提取出第一个标签 regexp_substr(str,'<[^>]+>') ---贪婪算法 regexp_substr(str,'<.+?>') ---非贪婪算法 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |