RegEx字符串可查找两个字符串并删除文件中的其余文本 [英] RegEx string to find two strings and delete the rest of the text in the file

查看:70
本文介绍了RegEx字符串可查找两个字符串并删除文件中的其余文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用记事本+++查找并删除文本文件中的其余部分 我想使用RegeX在thban上查找变体.....变量后面始终最多有5个字符(请参见圆点). 与我的搜索字符串,它撞到了最后一行,但整行.我只想保留这个词. 当这个工作的时候,我也想保留包含C3 .....的单词. tekst文件的其余部分可以删除. 还应该对大写不敏感

I need to do a find and delete the rest in a text file with notepad+++ i want tu use RegeX to find variations on thban..... the variable always has max 5 chars behind it(see dots). with my search string it hit the last line but the whole line. I just want the word preserved. When this works i also want keep the words containing C3..... The rest of a tekst file can be delete. It should also be caps insensitive

(?!thban\w+).*\r?\n?

\

THBANES900 and C3950 bla bla
THBAN
..THBANES901.. C3850 bla bla
THBANMP900
**..thbanes900..**

这应该导致

THBANES900 C3950
THBAN
THBANES901 C3850
THBANMP900
thbanes900

推荐答案

也许只是捕获那些令人感兴趣的单词,而不是替换其他所有单词?在Notepad ++中搜索模式:

Maybe just capture those words of interest instead of replacing everything else? In Notepad++ search for pattern:

^.*\b(thban\S{0,5})(?:.*(\sC3\w+))?.*$|.+

请参见在线演示

  • ^-开始字符串ancor.
  • .*\b-除换行符以外的任何字符,直到单词边界为止为零或多次.
  • (-打开第一个捕获组.
    • thban\S{0,5}-匹配"thban"和零或5个非空白字符.
    • )-关闭第一个捕获组.
    • ^ - Start string ancor.
    • .*\b - Any character other than newline zero or more times upto a word-boundary.
    • (- Open 1st capture group.
      • thban\S{0,5} - Match "thban" and zero or 5 non-whitespace chars.
      • ) - Close 1st capture group.
      • .*-除换行符以外的其他任何字符,均为零或多次.
      • (-打开第二个捕获组.
        • \sC3\w+-一个空格字符,匹配"C3"和一个或多个单词字符.
        • )-关闭第二个捕获组.
        • .* - Any character other than newline zero or more times.
        • ( - Open 2nd capture group.
          • \sC3\w+ - A whitespace character, match "C3" and one ore more word characters.
          • ) - Close 2nd capture group.

          替换为:

          $1$2
          


          此后,您可能会得到空行,可以使用内置选项巧妙地删除该行.我不知道英文字词,因此制作了一个GIF,向您展示在哪里可以找到这些按钮:


          After this, you may end up with empty line you can switly remove using the build-in option. I'm unaware of the english terms so I made a GIF to show you where to find these buttons:

          我不确定忽略大小写的英文复选按钮是什么.但是请确保未选中该选项.

          I'm not sure what the english checkbutton is for ignore case. But make sure that is not ticked.

          这篇关于RegEx字符串可查找两个字符串并删除文件中的其余文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆