简体   繁体   English

Perl 正则表达式详细信息

[英]Perl Regular Expression Details

There is a line $line =~ s/\\^M $// in a perl code. perl 代码中有一行$line =~ s/\\^M $// What does the regex s/\\^M $// mean?正则表达式s/\\^M $//是什么意思?

It means if $line contains the exact sub string ^M (hat-emm-space) at the end then remove it这意味着如果$line在末尾包含确切的子字符串^M (hat-emm-space) 然后将其删除

The reason for the initial backslash is that ^ has a special meaning in regexp and the backslash turns off the special meaning and makes it literally match初始反斜杠的原因是^在正则表达式中具有特殊含义,反斜杠关闭了特殊含义并使其字面匹配

The $ is an anchor to force a match at the end of the line $ 是在行尾强制匹配的锚点

Often ^M literal characters end up in files when copy paste is inappropriately used当复制粘贴使用不当时,通常 ^M 文字字符最终会出现在文件中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM