9.7.2. SIMILAR TO Regular Expressions

9.7.2.SIMILAR TO正则表达式

string SIMILAR TO pattern [ESCAPE escape-character]

string NOT SIMILAR TO pattern [ESCAPE escape-character]

The SIMILAR TO operator returns true or false depending on whether its pattern matches the given string. It is similar to LIKE, except that it interprets the pattern using the SQL standard's definition of a regular expression. SQL regular expressions are a curious cross between LIKE notation and common regular expression notation.

SIMILAR TO运算符根据其模式是否与给定的字符串匹配而返回true或false。它类似于LIKE,不同之处在于它使用SQL标准的正则表达式定义来解释模式。 SQL正则表达式是LIKE表示法和通用正则表达式表示法的一个综合。

Like LIKE, the SIMILAR TO operator succeeds only if its pattern matches the entire string; this is unlike common regular expression behavior where the pattern can match any part of the string. Also like LIKE, SIMILAR TO uses _ and % as wildcard characters denoting any single character and any string, respectively (these are comparable to . and .* in POSIX regular expressions).

像LIKE一样,SIMILAR TO运算符仅在其模式与整个字符串匹配时才成功;这与常见的正则表达式行为不同,在常规行为中,模式可以匹配字符串的任何部分。就像LIKE一样,SIMILAR TO使用_和%作为通配符,分别表示任何单个字符和任何字符串(它们与POSIX正则表达式中的.和.*相当)。

In addition to these facilities borrowed from LIKE, SIMILAR TO supports these pattern-matching metacharacters borrowed from POSIX regular expressions:

除了从LIKE借用的这些功能之外,SIMILAR TO还支持从POSIX正则表达式借用的这些模式匹配元字符:

• | denotes alternation (either of two alternatives).

• | 表示或(两种选择之一)。

• * denotes repetition of the previous item zero or more times.

• * 表示上一个项目重复零次或多次。

• + denotes repetition of the previous item one or more times.

• + 表示上一个项目重复一次或多次。

• ? denotes repetition of the previous item zero or one time.

• ? 表示重复上一个项目零或一次。

• {m} denotes repetition of the previous item exactly m times.

•{m}表示前一个项目正好重复m次。

• {m,} denotes repetition of the previous item m or more times.

•{m,}表示前一项重复m次或更多次。

• {m,n} denotes repetition of the previous item at least m and not more than n times.

•{m,n}表示前一项重复至少m次且不超过n次。

• Parentheses () can be used to group items into a single logical item.

•括号()可用于将项目分组为单个逻辑项目。

• A bracket expression [...] specifies a character class, just as in POSIX regular expressions.

•与POSIX正则表达式一样,括号表达式[...]指定字符类。

Notice that the period (.) is not a metacharacter for SIMILAR TO.

请注意,句点(.)不是SIMILAR TO的元字符。

As with LIKE, a backslash disables the special meaning of any of these metacharacters; or a different escape character can be specified with ESCAPE.

与LIKE一样,反斜杠会禁用所有这些元字符的特殊含义; 或可以使用ESCAPE指定其他转义字符。

Some examples:

示例:

'abc' SIMILAR TO 'abc' true

'abc' SIMILAR TO 'a' false

'abc' SIMILAR TO '%(b|d)%' true

'abc' SIMILAR TO '(b|c)%' false

'-abc-' SIMILAR TO '%\mabc\M%' true

'xabcy' SIMILAR TO '%\mabc\M%' false

带有三个参数的子字符串函数substring(来自转义字符的模式的字符串)提供与SQL正则表达式模式匹配的子字符串的提取功能。可根据SQL99语法使用该函数:

substring(string from pattern for escape-character)

或者简单写为具有三个参数的函数:

substring(string, pattern, escape-character)

与SIMILAR TO一样,指定的模式必须匹配整个数据字符串,否则函数将失败并返回null。为了指示成功时应返回的模式部分,该模式必须包含两次出现的转义字符,后跟双引号(“)。该函数将返回与这些标记之间的模式部分匹配的文本。

Some examples, with #" delimiting the return string:

使用#"作为分隔符的示例:

substring('foobar' from '%#"o_b#"%' for '#') oob

substring('foobar' from '#"o_b#"%' for '#') NULL

9.7.2. SIMILAR TO Regular Expressions相关推荐

  1. 8 Regular Expressions You Should Know

    2019独角兽企业重金招聘Python工程师标准>>> Regular expressions are a language of their own. When you learn ...

  2. 《D o C P》学习笔记(3 - 1)Regular Expressions, other languages and interpreters - Lesson 3

    备注1:每个视频的英文字幕,都翻译成中文,太消耗时间了,为了加快学习进度,我将暂停这个工作,仅对英文字幕做少量注释. 备注2:将.flv视频文件与Subtitles文件夹中的.srt字幕文件放到同1个 ...

  3. Coursera课程Python for everyone:Quiz: Regular Expressions

    Quiz: Regular Expressions 10 试题 1. Which of the following best describes "Regular Expressions&q ...

  4. 正则表达式(Regular Expressions)

    正则表达式(Regular Expressions) 正则表达式在其他编程语言中的应用非常广泛,网上资料也非常多,而网上在ABAP语言中应用的资料却很少,尽管各语言中正则表达式语法知识都很类似,但仍然 ...

  5. .NET Regular Expressions

    HTML去空白回车换行 private static readonly Regex REGEX_LINE_BREAKS = new Regex(@"\n\s*", RegexOpt ...

  6. Optimizing regular expressions in Java

    2019独角兽企业重金招聘Python工程师标准>>> SRC URL:http://www.javaworld.com/article/2077757/core-java/opti ...

  7. 《D o C P》学习笔记(3 - 0)Regular Expressions, other languages and interpreters - 简介

    Regular Expressions, other languages and interpreters 你可以学到什么: 定义正则表达式的语言:解释这个语言. 定义被1个正则表达式匹配的字符串集合 ...

  8. UltraEdit正则表达式使用(Regular Expressions in UltraEdit)

    正则表达式作为模式匹配,经常用于查找/替换操作的特定字符串.使用正则表达式来简化操作和提高效率的方式有许多.下面列出了一个用于ultra - edit样式和unix样式正则表达式的参考以及一些示例,演 ...

  9. 斯坦福大学Dan Jurafsky主讲NLP笔记 2.1 Regular Expressions

    2.1 regular expressions 正则表达式 2.1.1 问题的提出 在英语中,有大小写和单复数的问题,例如: woodchuck      woodchucks      Woodch ...

最新文章

  1. python错误找回_致命的Python错误:无法从堆栈溢出中恢复。洪水期间Fi
  2. LeetCode Maximal Rectangle(dp)
  3. rsync 服务与配置文档
  4. [css] 使用css实现霓虹灯效果
  5. 嵌入式linux写文件内存增加,嵌入式Linux对内存的直接读写
  6. Linux IPC实践(11) --System V信号量(1)
  7. SDS趋势之二:对象存储将替代文件存储
  8. phpstudy命令行中数据表插入中文显示不了的问题
  9. 基于vc的freetype字体轮廓解析_才一年,长安又换新LOGO,连带字体也升级了,你喜欢吗?_搜狐汽车...
  10. 禁忌搜索算法c语言代码,禁忌搜索算法
  11. 今日头条面试真题及答案,软件测试工程师面试秘籍
  12. win8.1装载windows和linux双系统
  13. 智能仓储系统作业流程及价值
  14. element 验证出现英文以及自动验证问题
  15. ORAN C平面 Section Type 0
  16. 余承东吐槽iPhone X长的丑体验差;雷军称小米明年要进世界500强;特斯拉股价被指太荒唐丨价值早报
  17. go语言判断文件是否为UTF8编码
  18. 图解域名解析成IP的全过程(你浏览器摁下一个网址后发生了啥?)
  19. 无人值守安装linux7,kickstart无人值守安装CentOS7
  20. 山洪灾害监测预警系统解决方案

热门文章

  1. 利用HTML5仿制百度首页
  2. mysql中配置general_log日志文件
  3. HUAWEI(17)——Mux-VLAN
  4. 计算机科学家霍金的预言,霍金的预言可能是真的!科学家刚探测到史上最强“外星人信号”...
  5. 当我成为独立开发者我在干什么
  6. Traceur 转码器
  7. [OpenGL] 雪景火焰特效demo
  8. 计算机毕设(附源码)JAVA-SSM泸定中学宿舍管理系统设计
  9. UIColor使用colorWithRed定义颜色
  10. Microbiome | 中大丁涛组揭示人体常见呼吸道病毒感染塑造的口咽菌群特征