RegEx string to find two strings and delete the rest of the text in the file

前端 未结 2 1288
滥情空心
滥情空心 2021-01-24 11:51

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 dot

2条回答
  •  无人及你
    2021-01-24 12:18

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

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

    See the Online Demo

    • ^ - 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.
    • (?: - Open non-capturing group.
      • .* - 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.
      • )? - Close non-capturing group and make it optional.
    • .* - Any character other than newline zero or more times.
    • $ - End string ancor.
    • | - Alternation (OR).
    • .+ - Any character other than newline once or more.

    Replace with:

    $1$2
    

    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.

提交回复
热议问题