ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

9.7. Pattern Matching

2021-01-11 13:29:36  阅读:261  来源: 互联网

标签:正则表达式 Pattern matching regular SQL pattern 9.7 SIMILAR Matching


9.7. Pattern Matching

9.7. 模式匹配

There are three separate approaches to pattern matching provided by PostgreSQL: the traditional SQL LIKE operator, the more recent SIMILAR TO operator (added in SQL:1999), and POSIX-style regular expressions. Aside from the basic “does this string match this pattern?” operators, functions are available to extract or replace matching substrings and to split a string at matching locations.

PostgreSQL提供了三种单独的模式匹配方法:传统的SQL LIKE运算符,SIMILAR TO运算符(在SQL:1999中添加)和POSIX样式的正则表达式。除了基本的“此字符串是否匹配此模式?”运算符,函数可用于提取或替换匹配的子字符串并在匹配的位置拆分字符串。

Tip

小贴士

If you have pattern matching needs that go beyond this, consider writing a user-defined function in Perl or Tcl.

如果有超出此范围的模式匹配需求,可以考虑使用Perl或Tcl编写用户自定义的函数。

 

Caution

注意

While most regular-expression searches can be executed very quickly, regular expressions can be contrived that take arbitrary amounts of time and memory to process. Be wary of accepting regular-expression search patterns from hostile sources. If you must do so, it is advisable to impose a statement timeout.

尽管大多数正则表达式搜索可以非常快速地执行,但却也可以构造能够耗费任意时间及内存去执行的正则表达式。因此从未知来源接受正则表达式的时候,一定要谨慎。如果必须这样做,则建议强制限制语句超时。

 

Searches using SIMILAR TO patterns have the same security hazards, since SIMILAR TO provides many of the same capabilities as POSIX-style regular expressions.

使用SIMILAR TO模式进行的搜索具有相同的安全隐患,因为SIMILAR TO提供了许多与POSIX样式正则表达式相同的功能。

 

LIKE searches, being much simpler than the other two options, are safer to use with possibly-hostile pattern sources.

与其他两个选项相比,LIKE搜索要简单得多,它与可能有害的模式源一起使用安全性会高一些。

标签:正则表达式,Pattern,matching,regular,SQL,pattern,9.7,SIMILAR,Matching
来源: https://blog.csdn.net/ghostliming/article/details/112465890

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有