Difference between revisions of "Search and Replace Tricks"

From EditPlus Wiki
Jump to: navigation, search
m
Line 76: Line 76:
 
Example: before: "this;is;an;example", after: "this|is;an;example"
 
Example: before: "this;is;an;example", after: "this|is;an;example"
  
Hi!
+
==Truncate last value from a MySQL INSERT query==
I'm shocked how cool this wesite is!
+
Find: "(VALUES \('...', '.+'), .+\);" ''(without quotes)''<br />
 +
Replace: "\1);" ''(without quotes)''<br />
 +
RegExp<br />
 +
Example: before: "INSERT INTO table VALUES ('value1','value2','value3');", after: "INSERT INTO table VALUES ('value1','value2');"
  
[http://jeeee.net/url/13460.html teen ass fuck] |
+
==Keep only last value in a MySQL INSERT query==
[http://jeeee.net/url/13456.html teen models] |
+
Find: "(VALUES \(.+,)(.+\);)" ''(without quotes)''<br />
[http://jeeee.net/url/13473.html tranny girls] |
+
Replace: "VALUES (\2" ''(without quotes)''<br />
[http://jeeee.net/url/13471.html thong girls]
+
RegExp<br />
 +
Example: before: "INSERT INTO table VALUES ('value1','value2','value3');", after: "INSERT INTO table VALUES ('value3');"
  
Excellent web site
+
==Truncate a string after the first occurrence of a marker (keeping the marker)==
I will visit it often.
+
Find: "^([^;]*;).*$" ''(without quotes)''<br />
BlackDad
+
Replace: "\1" ''(without quotes)''<br />
 
+
RegExp<br />
[http://s-url.net/0v2a big butts] |
+
Note: In this example, the marker is ";".<br />
[http://s-url.net/0uwe disney hentai comics] |
+
Example: before: "this;is;an;example", after: "this;"
[http://s-url.net/0uz3 sexy bikini babes] |
+
[http://s-url.net/0uzl perfect butt]
+
 
+
Hi!
+
I'm shocked how cool this wesite is!
+
 
+
[http://s-url.net/0uxi cum shot] |
+
[http://s-url.net/0uzk huge boobs] |
+
[http://s-url.net/0uux asian big boobs] |
+
[http://s-url.net/0uvx busty blonde]
+
  
 
==Truncate a string at the first occurrence of a marker (removing the marker too)==
 
==Truncate a string at the first occurrence of a marker (removing the marker too)==

Revision as of 18:55, 18 June 2007

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"

Truncate last value from a MySQL INSERT query

Find: "(VALUES \('...', '.+'), .+\);" (without quotes)
Replace: "\1);" (without quotes)
RegExp
Example: before: "INSERT INTO table VALUES ('value1','value2','value3');", after: "INSERT INTO table VALUES ('value1','value2');"

Keep only last value in a MySQL INSERT query

Find: "(VALUES \(.+,)(.+\);)" (without quotes)
Replace: "VALUES (\2" (without quotes)
RegExp
Example: before: "INSERT INTO table VALUES ('value1','value2','value3');", after: "INSERT INTO table VALUES ('value3');"

Truncate a string after 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: "this;"

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