Search code examples
regexreplacesubstringnotepad++textselection

Using Regex selecting text match everything after a word or patterns (similar topic but text is not fix patterns except 1 character)


I am trying to use Regex in notepad++ to select everything after v+(number|character)* but in the selection it should excluded the v+(num|char)*.

e.g. master\_\move_consolidate_archives_html_to_move_base_v2kjkj_(2021_01_19_11h43m59s-fi_m_dt xx-) - Copy (2).bat"

I am expecting

_(2021_01_19_11h43m59s-fi_m_dt xx-) - Copy (2).bat"

so far I can use this line (?i)(v\d[0-9a-z]*) to select v2kjkj

but I can't get this to work with lookbehind (?<=xxxx). I am also trying to use if-then-else condition but no luck for me. I am still don't understand enough to using it.

issue. because the "v" have different pattern in it. I can't hard code to certain string

v2
v23
v2kjkj
v2343434

Test string:

mmaster\_\move_consolidate_archives_html_to_move_base_v2_16_.bat"
master\_\move_consolidate_archiv es_html_to_move_base_v23_17_.bat"
master\_\move_consolidate_archives_html_to_move_base_v2_17_(2021_01_19_12h37m19s-fi_m_dt xx-).bat"
master\_\move_consolidate_archives_html_to_move_base_v2_(2021_01_19_11h43m59s-fi_m_dt xx-) - CopyCopy.bat"
master\_\move_consolidate_archives_html_to_move_base_v2kjkj_(2021_01_19_11h43m59s-fi_m_dt xx-) - Copy (2).bat"
master\_\move_consolidate_archives_html_to_move_base_v2343434_(2021_01_19_11h43m59s-fi_m_dt xx-) - Copy (3).bat"

I have been reading and searching for a day but I can't apply anything I have seen so for. the closest one I see was

  • Regexp match everything after a word
  • Getting the text that follows after the regex match

I am welcome any comments.


Solution

    • Ctrl+H
    • Find what: v\d[0-9a-z]*\K.*$
    • Replace with: LEAVE EMPTY
    • UNCHECK Match case
    • CHECK Wrap around
    • CHECK Regular expression
    • UNCHECK . matches newline
    • Replace all

    Explanation:

    v               # a "v"
    \d              # a digit
    [0-9a-z]*       # 0 or more alphanum
    \K              # forget all we have seen until this position
    .*              # 0 or more any character but newline
    $               # end of line
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here