Miss Phuong
Miss Phuong

Reputation: 289

Search and replace with Notepad++ keeping after defined string

I have a file with content:

http://domain1.tld/random1/random11/random111/file1.jpg
http://domain2.tld/random12/file2.jpg
http://domain3.tld/file3.jpg
http://sub1.domain4.tld/blah/blahblah/file4.jpg

I want to search and replace to:

file1.jpg
file2.jpg
file3.jpg
file4.jpg

Upvotes: 1

Views: 70

Answers (3)

Toto
Toto

Reputation: 91430

This removes everything upto the last slash in a line:

  • Ctrl+H
  • Find what: ^.+/
  • Replace with: LEAVE EMPTY
  • check Wrap around
  • check Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

^       # beginning of line
  .+    # 1 or more any character but newline
  /     # slash

Result for given example:

file1.jpg
file2.jpg
file3.jpg
file4.jpg

Upvotes: 0

CinCout
CinCout

Reputation: 9619

Use the following regex in find:

.+\/(.*)$

All it is doing is matching everything until a '\' is encountered (greedily) and then capturing everything till the end of the line.

Replace it with:

$1

Demo

Make sure you select the Regular Expression option in Notepad++. Note that this will also work for all file extensions, and not just .jpg.

Upvotes: 2

Yanis-git
Yanis-git

Reputation: 7875

On notepad++ you should find search and replace by regex pattern, then you can use this following regex as search criteria :

.+\/(\w+\.jpg)$ Be sure regex have multiline flag. this regex will capture each lines who looks like url/path whitch target jpg file and create temporally $1 where will be stored file name.

then you replace by :

$1\n

Upvotes: 1

Related Questions