Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 删除包含特定单词的行以及记事本中的前一行++;_Regex_Notepad++ - Fatal编程技术网

Regex 删除包含特定单词的行以及记事本中的前一行++;

Regex 删除包含特定单词的行以及记事本中的前一行++;,regex,notepad++,Regex,Notepad++,我想获得删除包含字符串/movie/和前一行的每一行的代码(/字符包含在/movie/中) 例如: 代码之前: #绝灭:-1,摧毁它,拉尔夫 http://p5.giffy.be:8080/movie/RghyHCIE4i/SDrQatrZkx/104880.mp4 #绝迹:-1,无皱纹 http://p5.giffy.be:8080/movie/RghyHCIE4i/SDrQatrZkx/105060.mp4 #绝迹:-1,DR | TELEMICRO 5 http://p5.giffy.be

我想获得删除包含字符串
/movie/
和前一行的每一行的代码(
/
字符包含在
/movie/
中)

例如:

代码之前:

#绝灭:-1,摧毁它,拉尔夫
http://p5.giffy.be:8080/movie/RghyHCIE4i/SDrQatrZkx/104880.mp4
#绝迹:-1,无皱纹
http://p5.giffy.be:8080/movie/RghyHCIE4i/SDrQatrZkx/105060.mp4
#绝迹:-1,DR | TELEMICRO 5
http://p5.giffy.be:8080/RghyHCIE4i/SDrQatrZkx/99633
#绝灭:-1,错误错误-短片
http://p5.giffy.be:8080/movie/RghyHCIE4i/SDrQatrZkx/106840.mp4
#绝灭:-1,TELESISTEMA博士11
http://p5.giffy.be:8080/RghyHCIE4i/SDrQatrZkx/99632
#绝灭:-1,摧毁它
http://p5.giffy.be:8080/movie/RghyHCIE4i/SDrQatrZkx/104707.mp4
#绝灭:-1,TELEUNIVERSO博士
http://p5.giffy.be:8080/RghyHCIE4i/SDrQatrZkx/99631
代码后:

#绝迹:-1,DR | TELEMICRO 5
http://p5.giffy.be:8080/RghyHCIE4i/SDrQatrZkx/99633
#绝灭:-1,TELESISTEMA博士11
http://p5.giffy.be:8080/RghyHCIE4i/SDrQatrZkx/99632
#绝灭:-1,TELEUNIVERSO博士
http://p5.giffy.be:8080/RghyHCIE4i/SDrQatrZkx/99631

您可以使用以下正则表达式:

^.*?\r\n.*?\/movie\/.*?(\r\n|$)
逐步:

  • 打开查找并替换为Ctrl+h
  • 按Alt+f键以集中精力查找内容
  • 输入上面的正则表达式
  • 按Alt+g以启用正则表达式模式。确保“.matches newline”处于禁用状态
  • 按Alt+a替换所有
  • 工作原理:

    ^  # anchor to beginning of line 
     .*?  # lazily match zero or more characters
        \r\n  # match carriage return and line feed
            .*?  # lazily match zero or more characters
               \/movie\/  # match literal /movie/
                        .*?  # lazily match zero or more characters
                           (\r\n|$)  # match carriage return and line feed or EOL
    

    另一个选项是匹配第一行并匹配unicode换行序列
    \R
    。然后将第二行与
    /movie/
    匹配,最后匹配
    \R

    查找内容:

    ^.*\R.*/movie/.*\R
    
    那会匹配的

    • ^
      字符串的开头
    • *
      匹配0+乘以除换行符以外的任何字符
    • \R
      匹配unicode换行符序列
    • */movie/*
      匹配字符串中的
      /movie/
    • \R
      匹配unicode换行符序列
    替换为:

    ^.*\R.*/movie/.*\R
    
    留空


    @ggorlen请查看我的编辑谢谢,您的代码运行良好,但遗漏了一点:例如,如果我的文本的最后一行包含/movie/,它会删除所有好的内容,但保留最后一行的原样,您能修复它吗这是因为最后一行没有以
    \r\n
    结尾。使用替换:
    (\r\n |$)