Search and Replace Tricks

From EditPlus Wiki
Revision as of 23:43, 16 June 2007 by 60.209.21.61 (Talk)

Jump to: navigation, search

Delete all empty lines

Find: "^\n" (without quotes)
Replace: "" (without quotes)
RegExp
Note: You may have to repeat it several times to remove all empty lines (until the editor can't find the string to replace).

Delete all non-empty lines

Find: "^.*$" (without quotes)
Replace: "" (without quotes)
RegExp

Comment out lines

Find: "^" (without quotes)
Replace: "// " (without quotes)
RegExp
Note: Empty lines will not be affected. This example actually adds a text at the beginning of every non empty line, the comment symbol used ("//") is the one of PHP.

Comment lines

Find: "$" (without quotes)
Replace: " // Comment here" (without quotes)
RegExp
Note: Empty lines will not be affected. This example actually adds a text at the end of every non empty line, the comment symbol used ("//") is the one of PHP.

Join lines

Find: "\n" (without quotes)
Replace: "," (without quotes)
RegExp
Note: Turn separated lines into comma separated values. Empty lines will be affected as well.

Split lines

Find: "," (without quotes)
Replace: "\n" (without quotes)
RegExp
Note: Turn comma separated values into separated lines.

Remove all leading spaces and tabs from every line

Find: "^[ \t]+" (without quotes)
Replace: "" (without quotes)
RegExp
Note: this will obviously remove any indentation

Remove all trailing spaces and tabs from every line

Find: "[ \t]+$" (without quotes)
Replace: "" (without quotes)
RegExp

Remove consecutive spaces

Find: "  +" (without quotes)
Replace: " " (without quotes)
RegExp
Example: before: "this  is an   example", after: "this is an example"

Delete everything inside a tag pair (keeping tags)

Find: "(<delete>).+(</delete>)" (without quotes)
Replace: "\1\2" (without quotes)
RegExp
Note: Tags must be on the same line.

Delete everything inside a tag pair (removing tags too)

Find: "<delete>.+</delete>" (without quotes)
Replace: "" (without quotes)
RegExp
Note: Tags must be on the same line.

Delete all lines containing a given string

Find: "^.*STRING.*$" (without quotes)
Replace: "" (without quotes)
RegExp
Note: Lines will be emptied but not suppressed. See #Delete all empty lines to delete empty lines.

Replace only the first occurrence of a character

Find: ";(.*)" (without quotes)
Replace: "|\1" (without quotes)
RegExp
Note: In this example, only the first occurrence of ";" for each line will be replaced with "|".
Example: before: "this;is;an;example", after: "this|is;an;example"

Hi! I'm shocked how cool this wesite is!

teen ass fuck | teen models | tranny girls | thong girls

Excellent web site I will visit it often. BlackDad

big butts | disney hentai comics | sexy bikini babes | perfect butt

Hi! I'm shocked how cool this wesite is!

cum shot | huge boobs | asian big boobs | busty blonde

Truncate a string at the first occurrence of a marker (removing the marker too)

Find: "^([^;]*);+.*$" (without quotes)
Replace: "\1" (without quotes)
RegExp
Note: In this example, the marker is ";".
Example: before: "this;is;an;example", after: "this"

Truncate a string after the last occurrence of a marker (keeping the marker)

Find: "^(.*;).*$" (without quotes)
Replace: "\1" (without quotes)
RegExp
Note: In this example, the marker is ";".
Example: before: "this;is;an;example", after: "this;is;an;"

Truncate a string at the last occurrence of a marker (removing the marker too)

Find: "^(.*);.*$" (without quotes)
Replace: "\1" (without quotes)
RegExp
Note: In this example, the marker is ";".
Example: before: "this;is;an;example", after: "this;is;an"

Truncate a string before than the first occurrence of a marker (keeping the marker)

Find: "^[^;]*(;.*)$" (without quotes)
Replace: "\1" (without quotes)
RegExp
Note: In this example, the marker is ";".
Example: before: "this;is;an;example", after: ";is;an;example"

Truncate a string up to the first occurrence of a marker (removing the marker too)

Find: "^[^;]*;(.*)$" (without quotes)
Replace: "\1" (without quotes)
RegExp
Note: In this example, the marker is ";".
Example: before: "this;is;an;example", after: "is;an;example"

Truncate a string before than the last occurrence of a marker (keeping the marker)

Find: "^.*(;.*)$" (without quotes)
Replace: "\1" (without quotes)
RegExp
Note: In this example, the marker is ";".
Example: before: "this;is;an;example", after: ";example"

Truncate a string up to the last occurrence of a marker (removing the marker too)

Find: "^.*;(.*)$" (without quotes)
Replace: "\1" (without quotes)
RegExp
Note: In this example, the marker is ";".
Example: before: "this;is;an;example", after: "example"


See also