




免费预览已结束,剩余4页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
_正则表达式(regex)是定义复杂查询的一个强有力的工具。这里是一个简单的资料,它忽略了一些详细的信息。 正则表达式定义了一个字符串的规则。最简单的正则表达式不包含任何保留字。例如,正则表达式hello只和字符串“hello”匹配。 一般的正则表达式使用了某些特殊的结构,所以它能匹配更多的字符串。例如,正则表达式hello|word既能匹配字符串“hello”也能匹配字符串 “word”。举一个更复杂一点的例子,正则表达式Ban*s可以匹配字符串“Bananas”、“Baaaaas” 、“Bs”以及其他任何以B开头以s结尾的字符串,中间可以包括任意个a和任意个n的组合。 一个正则表达式中的可以使用以下保留字 所匹配的字符串以后面的字符串开头 mysql select fonfo REGEXP fo$; - 0(表示不匹配) mysql select fofo REGEXP fo; - 1(表示匹配) $ 所匹配的字符串以前面的字符串结尾 mysql select fono REGEXP fono$; - 1(表示匹配) mysql select fono REGEXP fo$; - 0(表示不匹配) . 匹配任何字符(包括新行) mysql select fofo REGEXP f.*; - 1(表示匹配) mysql select fonfo REGEXP f.*; - 1(表示匹配) a* 匹配任意多个a(包括空串) mysql select Ban REGEXP Ba*n; - 1(表示匹配) mysql select Baaan REGEXP Ba*n; - 1(表示匹配) mysql select Bn REGEXP Ba*n; - 1(表示匹配) a+ 匹配任意多个a(不包括空串) mysql select Ban REGEXP Ba+n; - 1(表示匹配) mysql select Bn REGEXP Ba+n; - 0(表示不匹配) a? 匹配一个或零个a mysql select Bn REGEXP Ba?n; - 1(表示匹配) mysql select Ban REGEXP Ba?n; - 1(表示匹配) mysql select Baan REGEXP Ba?n; - 0(表示不匹配) de|abc 匹配de或abc mysql select pi REGEXP pi|apa; - 1(表示匹配) mysql select axe REGEXP pi|apa; - 0(表示不匹配) mysql select apa REGEXP pi|apa; - 1(表示匹配) mysql select apa REGEXP (pi|apa)$; - 1(表示匹配) mysql select pi REGEXP (pi|apa)$; - 1(表示匹配) mysql select pix REGEXP (pi|apa)$; - 0(表示不匹配) (abc)* 匹配任意多个abc(包括空串) mysql select pi REGEXP (pi)*$; - 1(表示匹配) mysql select pip REGEXP (pi)*$; - 0(表示不匹配) mysql select pipi REGEXP (pi)*$; - 1(表示匹配) 1 2,3 这是一个更全面的方法,它可以实现前面好几种保留字的功能 a* 可以写成a0, a+ 可以写成a1, a? 可以写成a0,1 在内只有一个整型参数i,表示字符只能出现i次;在内有一个整型参数i,后面跟一个“,”,表示字符可以出现i次或i次以上;在内只有 一个整型参数i,后面跟一个“,”,再跟一个整型参数j,表示字符只能出现i次以上,j次以下(包括i次和j次)。其中的整型参数必须大于等于0,小于等 于 RE_DUP_MAX(默认是255)。如果有两个参数,第二个必须大于等于第一个 a-dX 匹配“a”、“b”、“c”、“d”或“X” a-dX 匹配除“a”、“b”、“c”、“d”、“X”以外的任何字符。“”、“”必须成对使用 mysql select aXbc REGEXP a-dXYZ; - 1(表示匹配) mysql select aXbc REGEXP a-dXYZ$; - 0(表示不匹配) mysql select aXbc REGEXP a-dXYZ+$; - 1(表示匹配) mysql select aXbc REGEXP a-dXYZ+$; - 0(表示不匹配) mysql select gheis REGEXP a-dXYZ+$; - 1(表示匹配) mysql select gheisa REGEXP a-dXYZ+$; - 0(表示不匹配) - .characters.表示比较元素的顺序。在括号内的字符顺序是唯一的。但是括号中可以包含通配符, 所以他能匹配更多的字符。举例来说:正则表达式.ch.*c匹配chchcc的前五个字符。 =character_class= 表示相等的类,可以代替类中其他相等的元素,包括它自己。例如,如果o和(+)是一个相等的类的成员,那么=o=、=(+)=和o(+)是完全等价的。 :character_class: 在括号里面,在:和:中间是字符类的名字,可以代表属于这个类的所有字符。 字符类的名字有: alnum、digit、punct、alpha、graph、space、blank、lower、upper、cntrl、print和xdigit mysql select justalnums REGEXP :alnum:+; - 1(表示匹配) mysql select ! REGEXP :alnum:+; - 0(表示不匹配) : 分别匹配一个单词开头和结尾的空的字符串,这个单词开头和结尾都不是包含在alnum中的字符也不能是下划线。 mysql select a word a REGEXP :; - 1(表示匹配) mysql select a xword a REGEXP :; - 0(表示不匹配) mysql select weeknights REGEXP (wee|week)(knights|nights)$; - 1(表示匹配)Description of MySQL regular expression syntax A regular expression (regex) is a powerful way of specifying a complex search. MySQL uses regular Henry Spencers inplementation of regular expressions. And that is aimed to conform to POSIX 1003.2. MySQL uses the extended version. This is a simplistic reference that skips the details. To get more exact information, see Henry Spencers regex(7) manual page that is included in the source distribution. See section C Contributors to MySQL. A regular expression describes a set of strings. The simplest regexp is one that has no special characters in it. For example, the regexp hello matches hello and nothing else. Nontrivial regular expressions use certain special constructs so that they can match more than one string. For example, the regexp hello|word matches either the string hello or the string word. As a more complex example, the regexp Ban*s matches any of the strings Bananas, Baaaaas, Bs and any other string starting with a B, ending with an s, and containing any number of a or n characters in between. A regular expression may use any of the following special characters/constructs: Match the beginning of a string. mysql select fonfo REGEXP fo$; - 0mysql select fofo REGEXP fo; - 1$ Match the end of a string. mysql select fono REGEXP fono$; - 1mysql select fono REGEXP fo$; - 0. Match any character (including newline). mysql select fofo REGEXP f.*; - 1mysql select fonfo REGEXP f.*; - 1a* Match any sequence of zero or more a characters. mysql select Ban REGEXP Ba*n; - 1mysql select Baaan REGEXP Ba*n; - 1mysql select Bn REGEXP Ba*n; - 1a+ Match any sequence of one or more a characters. mysql select Ban REGEXP Ba+n; - 1mysql select Bn REGEXP Ba+n; - 0a? Match either zero or one a character. mysql select Bn REGEXP Ba?n; - 1mysql select Ban REGEXP Ba?n; - 1mysql select Baan REGEXP Ba?n; - 0de|abc Match either of the sequences de or abc. mysql select pi REGEXP pi|apa; - 1mysql select axe REGEXP pi|apa; - 0mysql select apa REGEXP pi|apa; - 1mysql select apa REGEXP (pi|apa)$; - 1mysql select pi REGEXP (pi|apa)$; - 1mysql select pix REGEXP (pi|apa)$; - 0(abc)* Match zero or more instances of the sequence abc. mysql select pi REGEXP (pi)*$; - 1mysql select pip REGEXP (pi)*$; - 0mysql select pipi REGEXP (pi)*$; - 11 2,3 The is a more general way of writing regexps that match many occurrences of the previous atom. a* Can be written as a0,. a+ Can be written as a1,. a? Can be written as a0,1. To be more precise, an atom followed by a bound containing one integer i and no comma matches a sequence of exactly i matches of the atom. An atom followed by a bound containing one integer i and a comma matches a sequence of i or more matches of the atom. An atom followed by a bound containing two integers i and j matches a sequence of i through j (inclusive) matches of the atom. Both arguments must 0 = value select aXbc REGEXP a-dXYZ; - 1mysql select aXbc REGEXP a-dXYZ$; - 0mysql select aXbc REGEXP a-dXYZ+$; - 1mysql select aXbc REGEXP a-dXYZ+$; - 0mysql select gheis REGEXP a-dXYZ+$; - 1mysql select gheisa REGEXP a-dXYZ+$; - 0.characters. The sequence of characters of that collating element. The sequence is a single element of the bracket expressions list. A bracket expression containing a multi-character collating element can thus match more than one character, e.g., if the collating sequence includes a ch collating element, then the regular expression .ch.*c matches the first five characters of chchcc. =character_class= An equivalence class, standing for the sequences of characters of all collating elements equivalent to that one, including itself. For example, if o and (+) are the members of an equivalence class, then =o=, =(+)=, and o(+) are all synonymous. An equivalence class may not be an endpoint of a range. :character_class: Within a bracket expression, the name of a character class enclosed in : and : stands for the list of all characters belonging to that class. Standard character class names are: alnum digit punct alpha g
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 企业研发人员劳动合同解除与离职技术成果转移合同
- 亲子度假村游乐场地租赁与度假产品开发合同
- 2025年上海工艺美术职业学院招聘(5人)模拟试卷附答案详解(考试直接用)
- 离婚协议彩礼退还与房产、车辆分割合同范本
- 2025年单招数学高考试卷及答案
- 2025年广东广州市南沙区委办公室招聘编外人员笔试备考题库及参考答案详解
- 2025年河南省登封市中考数学试题预测试卷及参考答案详解【满分必刷】
- 2025资料员之资料员基础知识考试黑钻押题含完整答案详解(名师系列)
- 构建人才校企联合培养体系的策略及实施路径
- 锈钢新产业园项目招商引资报告
- 牛津深圳版九年级上册Module 1 Geniuses Unit1 Wise Man in History话题作文期末复习
- DB37T 5151-2019 园林绿化工程资料管理规程
- 电能表生产流程
- 心电图机操作(课堂PPT)
- 贝多芬F大调浪漫曲—小提琴谱(带钢伴谱)
- 科远DCS系统方案
- 压力传感器(课堂PPT)
- 动物的家ppt课件
- Tip-edge Plus差动直丝弓技术
- 深圳市政府投资市政工程施工质量检查用表
- 外销合同样本中英文
评论
0/150
提交评论