How to match a newline \n in a perl regex?

后端 未结 3 1120
太阳男子
太阳男子 2021-01-12 04:34

I want to match this line,

\'\'\'No Change Alarms Help & Information
相关标签:
3条回答
  • 2021-01-12 05:06

    All I needed was /gm on the end of my query, turns out it ignores new lines by default.

    0 讨论(0)
  • 2021-01-12 05:14
    $string_given =~ s/matching expression/sustitution/s;
    

    i think this will work,using the /s modifier, which mnemonically means to "treat string as a single line". This changes the behaviour of "." to match newline characters as well.

    In order to match the beginning of this comment to the end, we add the /s modifier like this:

    $str =~ s/<!-- Start.*End of section -->//s;
    

    Without the /s, it wouldn't match at all.

    0 讨论(0)
  • 2021-01-12 05:18

    In some cases it might not work because of how perl "slurps" the input. Passing -0777 as a parameter will make it consider multiple lines. (Pass it along with your other parameters, e.g. perl -0777pi -e)

    0 讨论(0)
提交回复
热议问题