14

how to find and replace all characters after the main domain (including the "/" character) using a wild card?

For example, i have the following 4 rows:

intersport-schaeftlmaier.de/
weymouthhondapowersports.com/Default.asp
rtbstream.com/click?data=RG1kUFJQQUYw
top-casino-sites.com/

In excel I would simply use the following: Find this /* Replace with this

The results will look like this:

intersport-schaeftlmaier.de
weymouthhondapowersports.com
rtbstream.com
top-casino-sites.com

So, how to do that with notepad++ ?

Thanks, Ziv

Ziv
  • 151
  • 1
  • 1
  • 6

4 Answers4

22

In the Find and Replace dialog:

  • under Search Mode select Regular Expression
  • set Find What to /.*$
  • leave Replace With empty

This is replace any slash and all the text after it until the end of line with nothing. It uses a regular expression so it looks convoluted but it is well worth learning as regular expressions are insanely useful for lots of things.

Basically:

  • / isn't a special character so it just matches a /
  • . is a wildcard that matches a single character. To match a literal . use \.
  • * is a wildcard that matches zero of more of the preceding character. So a* would match zero or more a and .* would match zero of more of any character.
  • $ matches the end of a line. To match a literal $ use \$

A few other special characters:

  • \ is the escape character - use it to turn special characters into normal characters. Yo match a literal \ use \\
  • + is a wildcard that matches one of more of the preceding character. So a+ would match one or more a and .+ would match one of more of any character.
  • ^ matches the start of a line. To match a literal ^ use \^
  • ( and ) make a match group. To match literal ( or ) use \( and \)

And there are more special characters including [, ], { and } along with others that I won't mention.

Jerry Jeremiah
  • 9,045
  • 2
  • 23
  • 32
2

Use Regular Expression in Replace and then use this:

/.*

Untick the . matches newline and ofc replace it with nothing ;)

Mono
  • 742
  • 6
  • 18
2

You may use (better regexp as Excel)

/.*

So:

Notepad search replace

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
  • In my case I didn't need `/` I only typed `.*` for example I was searching for `script.*scr` in a document to find `` – Shayan May 03 '19 at 17:43
1

Search -> Replace. In the Find what box, enter the following Regex:

/.*$

In the Replace with box, enter nothing. Make sure Search Mode is set to Regular expression. Then Find Next/Replace or Replace All as you see fit.

How it works:

/ matches /, ensuring we start from the / after the domain name.
.* matches any character any number of times.
$ anchors the match to the end of the line.

In summary, this regex looks for / followed by any number of characters, all the way to the end of the line.

cf-
  • 8,598
  • 9
  • 36
  • 58