当前位置: 首页 > news >正文

红酒手机网站建设邢台微信网站

红酒手机网站建设,邢台微信网站,小程序api函数,网站建设方案怎么写目录 一、测试数据 二、简单模式匹配 1. 匹配字面值 2. 匹配数字和非数字字符 3. 匹配单词与非单词字符 4. 匹配空白字符 5. 匹配任意字符 6. 匹配单词边界 7. 匹配零个或多个字符 8. 单行模式与多行模式 一、测试数据 这里所用文本是《学习正则表达式》这本书带的是《抒情歌谣集》Lyrical Ballads, London, J.A. Arch, 1798中收录的塞缪尔·泰勒·柯勒律治的一首诗“The Rime of the Ancient” 的前几行。为了演示正则表达式的单行模式与多行模式特意生成了带有换行符ascii 10的单个行和不带换行符的多个行。 drop table if exists t_regexp; create table t_regexp(a text); insert into t_regexp values ( THE RIME OF THE ANCYENT MARINERE, IN SEVEN PARTS. ARGUMENT. How a Ship having passed the Line was driven by Storms to the cold Country towards the South Pole; and how from thence she made her course to the tropical Latitude of the Great Pacific Ocean; and of the strange things that befell; and in what manner the Ancyent Marinere came back to his own Country. I. 1       It is an ancyent Marinere, 2          And he stoppeth one of three: 3       By thy long grey beard and thy glittering eye 4          Now wherefore stoppest me?);insert into t_regexp values (THE RIME OF THE ANCYENT MARINERE, IN SEVEN PARTS.), (ARGUMENT.), (How a Ship having passed the Line was driven by Storms to the cold Country), (towards the South Pole; and how from thence she made her course to the tropical), (Latitude of the Great Pacific Ocean; and of the strange things that befell;), (and in what manner the Ancyent Marinere came back to his own Country.), (I.), (1       It is an ancyent Marinere,), (2          And he stoppeth one of three:), (3       By thy long grey beard and thy glittering eye), (4          Now wherefore stoppest me?); 二、简单模式匹配 1. 匹配字面值 匹配字符串字面值的方法就是使用普通的字符。例如 regexp_like(a,Ship) 函数的意思是匹配字段 a 中带有 Ship 文本的行缺省不区分大小写。执行结果如下 mysql select a from t_regexp where regexp_like(a,Ship)\G *************************** 1. row *************************** a: THE RIME OF THE ANCYENT MARINERE, IN SEVEN PARTS. ARGUMENT. How a Ship having passed the Line was driven by Storms to the cold Country towards the South Pole; and how from thence she made her course to the tropical Latitude of the Great Pacific Ocean; and of the strange things that befell; and in what manner the Ancyent Marinere came back to his own Country. I. 1       It is an ancyent Marinere, 2          And he stoppeth one of three: 3       By thy long grey beard and thy glittering eye 4          Now wherefore stoppest me? *************************** 2. row *************************** a: How a Ship having passed the Line was driven by Storms to the cold Country 2 rows in set (0.00 sec) 2. 匹配数字和非数字字符 以下三个查询等价都是匹配字段 a 中带有数字的行。 select a from t_regexp where regexp_like(a,[0123456789]); select a from t_regexp where regexp_like(a,[0-9]); select a from t_regexp where regexp_like(a,\\d); 匹配以数字开头的行 select a from t_regexp where regexp_like(a,^\\d); 匹配纯数字行 select a from t_regexp where regexp_like(a,^\\d$); 使用字符组可精确匹配字符。数字的字符组简写式 \d 更为简短但却没有字符组强大、灵活。在无法使用 \d 时不是所有情况下都支持这种方式或者想匹配特定数字时就需要使用字符组合适的时候可以使用 \d因为它更简短。 以下四个查询等价都是匹配字段 a 中带有非数字的行。 select a from t_regexp where regexp_like(a,[^0123456789]); select a from t_regexp where regexp_like(a,[^0-9]); select a from t_regexp where regexp_like(a,[^\\d]); select a from t_regexp where regexp_like(a,\\D); 匹配纯字母行 select * from t_regexp where regexp_like(a,^\\D$); 要匹配非数字字符可使用包含以下大写字母D的简写式 \D。注意字符组中括号内中的 ^ 符号不再代表行头而是表示取反意思其实就是“不匹配这些”或“匹配除这些以外的内容”。 3. 匹配单词与非单词字符 \w 简写式将匹配所有的单词字符\D 与 \w 的区别是 \D 会匹配空格、标点符号引号、连字符、反斜杠、方括号等字符而 \w 只匹配字母、数字和下划线。在英语环境中与 \w 匹配相同内容的字符组为[_a-zA-Z0-9] \W 匹配非单词字符匹配空格、标点以及其他非字母、非数字字符。使用以下字符组也可以匹配相同的内容[^_a-zA-Z0-9] 下表提供了更多的字符简写式。 字符简写式 描述 \a 报警符 [\b] 退格字符 \c x 控制字符 \d 数字字符 \D 非数字字符 \w 单词字符 \W 非单词字符 \0 空字符 \x xx 字符的十六进制值 \o xxx 字符的八进制值 \u xxx 字符的Unicode值 匹配所有emoji表情 select userid,nickname from space_user where regexp_like(nickname,(\\ud83c[\\udf00-\\udfff])|(\\ud83d[\\udc00-\\ude4f\\ude80-\\udeff])|[\\u2600-\\u2B55]) limit 10; \w 不匹配符号 select regexp_like((),\\w),regexp_like((),\\W),regexp_like((),\\D); 匹配电子邮箱 select regexp_like(wxy0327sohu.com,\\w[-\\w.]*([A-Za-z0-9][-A-Za-z0-9]\.)[A-Za-z]{2,14}); 4. 匹配空白字符 \s 与 [ \t\n\r] 字符组匹配的内容相同它会匹配空格、制表符\t、换行符\n、回车符\r。\s也有对应的大写形式如要匹配非空白字符使用 \S 或 [^ \t\n\r] 或 [^\s]。 下表列出了匹配常见和不太常见的空白字符的简写式。 字符简写式 描述 \f 换页符 \h 水平空白符 \H 非水平空白符 \n 换行符 \r 回车符 \s 空白符 \S 非空白符 \t 水平制表符 \v 垂直制表符 \V 非垂直制表符 5. 匹配任意字符 用正则表达式匹配任意字符的一种方法就是使用点号U002E。点号可以匹配除行结束符之外的所有字符个别情况除外。要匹配THE RIME整个短语则可使用八个点号但推荐用量词 .{8} 这个表达式就能匹配前两个单词以及它们之间的空格但只是粗略地匹配。从 https://www.dute.org/regex 看看这个表达式有什么作用就知道这里所说的粗略是什么意思了。它匹配了连续多组的八个字符头尾相连只有目标文本的最后几个字符除外。 6. 匹配单词边界 下面我们再试试匹配单词的边界和字母的开始和结束位置 \bA.{5}T\b 可以看到细微的差异 这个表达式有更强的特指性请记住特指性specificity这个概念很重要它匹配单词ANCYENT。简写式 \b 匹配单词边界不消耗任何字符字符 A 和 T 限定了字符序列的首尾字母.{5} 匹配任意五个字符简写式 \b 匹配单词的另一个边界。 现在再试一下这个简写式 \b\w{7}\b 结果如下图所示。 7. 匹配零个或多个字符 最后再试试匹配零个或多个字符 .* 它就相当于 [^\n] 或 [^\n\r]。类似地点号也可以与表示“一个或多个”的量词连用 . 8. 单行模式与多行模式 单行模式single line mode使得通配符点 . 匹配所有字符包括换行符。多行模式multi-line mode使得 ^ 和 $ 匹配到每行字符串的开头和结尾处。从这个定义可以看到所谓单行模式与多行模式分别用来限定 . 与 ^ $ 的行为而不像字面看起来表示单行或多行。因此这两种模式也不是互斥的可以共用、使用其中一个或都不使用MySQL中的正则缺省就是都不使用。实际上用 dotall 表示单行模式更为恰当下一篇演示 dotall 的例子这里用测试数据说明多行模式。需求是给 T 或 t 开头的行首尾分别加 HTML 标记 h1 与 \h1。 select regexp_replace(a,(^T.*$),h1$1\h1,1,0,im) from t_regexp limit 1\G 结果如下第一行和第四行加了标签符合预期。 h1THE RIME OF THE ANCYENT MARINERE, IN SEVEN PARTS.h1 ARGUMENT. How a Ship having passed the Line was driven by Storms to the cold Country h1towards the South Pole; and how from thence she made her course to the tropicalh1 Latitude of the Great Pacific Ocean; and of the strange things that befell; and in what manner the Ancyent Marinere came back to his own Country. I. 1       It is an ancyent Marinere, 2          And he stoppeth one of three: 3       By thy long grey beard and thy glittering eye 4          Now wherefore stoppest me? regexp_replace 函数的参数说明 a需要被替换的原字符串字段。(^T.*$)正则表达式匹配 T 开头的行然后使用括号将文本捕获到一个分组中。h1$1\h1替换表达式将 $1 捕获的内容嵌套在了 h1 标签中。1开始搜索位置缺省为1。0替换第几次匹配缺省为0表示替换所有匹配。im匹配类型i 表示不区分大小写m 表示多行匹配模式。如果不加 m会将整个字符串当做单一字符串则只能匹配出第一行。 现在修改需求为给每行首尾分别加 HTML 标记 h1 与 \h1。 select regexp_replace(a,(^.*$),h1$1\h1,1,0,im) from t_regexp limit 1\G 结果如下 h1THE RIME OF THE ANCYENT MARINERE, IN SEVEN PARTS.h1 h1ARGUMENT.h1 h1How a Ship having passed the Line was driven by Storms to the cold Countryh1 h1towards the South Pole; and how from thence she made her course to the tropicalh1 h1Latitude of the Great Pacific Ocean; and of the strange things that befell;h1 h1and in what manner the Ancyent Marinere came back to his own Country.h1 h1I.h1 h11       It is an ancyent Marinere,h1 h12          And he stoppeth one of three:h1 h13       By thy long grey beard and thy glittering eyeh1 h14          Now wherefore stoppest me?h1 捕获分组中的 ^.*$ 说明 ^ 匹配字符串的第一个字符之前的位置。$ 匹配字符串的最后一个字符后面的位置。. 匹配单个字符。除了换行符之外它的性质无关紧要。* 匹配前一个匹配零次或多次。 因此^.*$ 表示从头到尾匹配任何出现零次或多次的字符。基本上这意味着匹配从字符串的开头到结尾的所有内容。注意这里的 . 一定要有否则只会在每行最后添加一对标签 THE RIME OF THE ANCYENT MARINERE, IN SEVEN PARTS.h1h1 ARGUMENT.h1h1 How a Ship having passed the Line was driven by Storms to the cold Countryh1h1 towards the South Pole; and how from thence she made her course to the tropicalh1h1 Latitude of the Great Pacific Ocean; and of the strange things that befell;h1h1 and in what manner the Ancyent Marinere came back to his own Country.h1h1 I.h1h1 1       It is an ancyent Marinere,h1h1 2          And he stoppeth one of three:h1h1 3       By thy long grey beard and thy glittering eyeh1h1 4          Now wherefore stoppest me?h1h1
http://www.sczhlp.com/news/177964/

相关文章:

  • 企业网站的设计与开发精英学校老师给学生做的网站
  • 语种网站建设市场营销女生好就业吗?
  • 广州网站制作公司 番禺wordpress 文件
  • 代做施组 方案的网站资源网站建设
  • 将电脑做的网站放到外网网站logo教程
  • 大型网站架构实战宣传片制作的十大步骤
  • 做外贸在哪个网站注册新浦网站制作网站建设
  • 建设网站需要的软硬件定制网站建设流程
  • 怎么在百度做公司网站四川十大设计院
  • 城乡与建设厅网站代做网站的好处
  • 网站建设主要产品wordpress快递主题
  • Semantic Kernel + AutoGen = 开源 Microsoft Agent Framework
  • wap网站分享到微信襄樊和襄阳是一个地方吗
  • 最新钓鱼网站源码常州哪些网站公司做的好处
  • 网站加手机建设png图标网站制作算是什么专业
  • 网站上的分享济南国迅网站建设公司怎么样
  • 网站建设制作公司 首推万维科技杭州微官网设计公司
  • 快速建站php化工建设网站
  • 昆明营销型网站建设福州高端网站建设服务网络公司
  • 有人做几个蝎子养殖门户网站二级域名注册
  • 做外贸网站策划wordpress仿制模块
  • 做外掛网站空间做网站赚广告费好做吗
  • 成都都江堰网站建设电脑上如何做网站宣传
  • 网站建设需要花多少钱浙江省信息港官网
  • 手工做环保衣的网站房地产政策政策最新消息
  • 企业网站的建立标准公司网站背景图片
  • WordPress站内搜索代码网络营销策划过程
  • flash网站链接怎么做手机网站智能管理系统
  • 设计网站教程淘宝店铺怎么引流推广
  • 网站首页建设中页面河北省住房和城乡建设厅网站主页