zoukankan      html  css  js  c++  java
  • perl学习之:匹配修饰符/s /m

    m 是将字符串作为多行处理,s是将字符串作为单行处理,如果是s在字符串中出现的 就相当于普通字符。

    6.6. Matching Within Multiple Lines
    6.6.1. Problem
    You want to use regular expressions on a string containing more than one logical line, but the special characters . (any character but newline), ^ (start of string), and $ (end of string) don't seem to work for you. This might happen if you're reading in multiline records or the whole file at once.

    6.6.2. Solution
    Use /m, /s, or both as pattern modifiers. /s allows . to match a newline (normally it doesn't). If the target string has more than one line in it, /foo.*bar/s could match a "foo" on one line and a "bar" on a following line. This doesn't affect dots in character classes like [#%.], since they are literal periods anyway.

    The /m modifier allows ^ and $ to match immediately before and after an embedded newline, respectively. /^=head[1-7]/m would match that pattern not just at the beginning of the record, but anywhere right after a newline as well.

  • 相关阅读:
    成员对象和封闭类
    静态成员
    this指针
    类型构造构造函数
    拷贝构造函数
    C++
    矩阵快速幂求递推式
    对浅拷贝和深拷贝的基本理解
    传引用作为形参和返回值_节省参数拷贝的时间
    namespace的基本知识
  • 原文地址:https://www.cnblogs.com/chip/p/4271518.html
Copyright © 2011-2022 走看看