zoukankan      html  css  js  c++  java
  • ruby中的z与区别

     1 s = "this is
    the name
    "
     2 puts "--------------"
     3 puts s.match(/name/)
     4 puts s.match(/namez/)
     5 puts "--------------"
     6 
     7 s = "this is
    the name"
     8 puts "--------------"
     9 puts s.match(/name/)
    10 puts s.match(/namez/)
    11 puts "--------------"
    1 --------------
    2 name
    3 
    4 --------------
    5 --------------
    6 name
    7 name
    8 --------------

     官方文档是

    •  - Matches end of string. If string ends with a newline, it matches just before newline

    • z - Matches end of string

    我的理解是和z都是匹配字符串的结尾,但是如果字符串结尾多了一个 ,那么匹配时忽略这个 ,匹配 前面的内容是否与给定的正则匹配,而z不能忽略,所以z会失败,如上面例子

  • 相关阅读:
    正则表达式之re模块
    collections模块
    openpyxl模块
    hashlib模块
    random模块
    os模块
    sys模块
    nodeType
    数据类型转换
    添加删除
  • 原文地址:https://www.cnblogs.com/or2-/p/6538322.html
Copyright © 2011-2022 走看看