str = str.replace(”find”,”replace”)
To ReplaceAll you have to do it a little differently. To replace all occurrences in the string, use the g modifier like this:
str = str.replace(/find/g,”replace”)
My Knowledges
str = str.replace(”find”,”replace”)
str = str.replace(/find/g,”replace”)
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), because only the first one of a series of consecutive empty lines will be edited.
Find: "^.+$" (without quotes)
Replace: "" (without quotes)
RegExp
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.
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.
Find: "\n" (without quotes)
Replace: "," (without quotes)
RegExp
Note: Turn separated lines into comma separated values. Empty lines will be affected as well.
Find: "," (without quotes)
Replace: "\n" (without quotes)
RegExp
Note: Turn comma separated values into separated lines. Consecutive commas will generate empty lines.
Find: "^[ \t]+" (without quotes)
Replace: "" (without quotes)
RegExp
Note: this will obviously remove any indentation
Find: "[ \t]+$" (without quotes)
Replace: "" (without quotes)
RegExp
Find: " +" (without quotes)
Replace: " " (without quotes)
RegExp
Example: before: "this is an example", after: "this is an example"
Find: "([\.\,\;\:\?\!])([a-zA-Z])" (without quotes)
Replace: "\1 \2" (without quotes)
RegExp
Example: before: "How are you?I'm fine,thanks.", after: "How are you? I'm fine, thanks."
Note: If you want to use this statement in a Wiki context, remove "\:" from the search string, otherwise you may break Wiki metatags, for example [[Category:Example]] will be replaced by [[Category: Example]]
Find: "(bold)" (without quotes)
Replace: "\1" (without quotes)
RegExp
Example: before: "bold", after: "bold"
Find: "^(.+)$" (without quotes)
Replace: "
Find: "(
Replace: "\1\2" (without quotes)
RegExp
Note: Tags must be on the same line.
Example: before: "this
Find: "
Replace: "" (without quotes)
RegExp
Note: Tags must be on the same line.
Example: before: "this
Find: "^.*STRING.*$" (without quotes)
Replace: "" (without quotes)
RegExp
Note: Lines will be emptied but not suppressed. See #Suppress all empty lines to suppress empty lines.
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"
Find: "(.*);" (without quotes)
Replace: "\1|" (without quotes)
RegExp
Note: In this example, only the last occurrence of ";" for each line will be replaced with "|".
Example: before: "this;is;an;example", after: "this;is;an|example"
Find: "^([^;]*;).*$" (without quotes)
Replace: "\1" (without quotes)
RegExp
Note: In this example, the marker is ";".
Example: before: "this;is;an;example", after: "this;"
Find: "^([^;]*);+.*$" (without quotes)
Replace: "\1" (without quotes)
RegExp
Note: In this example, the marker is ";".
Example: before: "this;is;an;example", after: "this"
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;"
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"
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"
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"
Find: "^.*(;.*)$" (without quotes)
Replace: "\1" (without quotes)
RegExp
Note: In this example, the marker is ";".
Example: before: "this;is;an;example", after: ";example"
Find: "^.*;(.*)$" (without quotes)
Replace: "\1" (without quotes)
RegExp
Note: In this example, the marker is ";".
Example: before: "this;is;an;example", after: "example"
"^([^\,]+)\,([^\,]+)\,([^\,]+)$" (without quotes)
"elseif (vcmp$=="\1") {$v2="\2"; $v3="\3";}" (without quotes)
RegExp
Example: before: "Italy,Rome,Euro", after: elseif (vcmp$=="Italy") {$v2="Rome"; $v3="Euro";}
Note: In this example, there are three values per record, and the CSV separator is a comma (,), you may need to replace it with another character like \t for tab. Remember to change the first "elseif" to "if".
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');"
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');"
Find: "`[^`]*`([\,\)\'\"])" (without quotes)
Replace: "''\1" (without quotes)
RegExp
Example: before: "INSERT INTO table (`phone`,`phonecell`,`fax`) VALUES (`phone`,`phonecell`,`fax`);", after: "INSERT INTO table (`phone`,`phonecell`,`fax`) VALUES ('','','');". (Only the second instance of "(`phone`,`phonecell`,`fax`)" must be selected and search and replace must be applied to such selection).
Note: this is meant to replicate the values in a INSERT query according to the specified fields (and use the empty values as a placeholder): you simply need to copy the fields and past them after VALUES, and then replace them this way.
Find: "(\*)(.*)$" (without quotes)
Replace: "\1[[\2]]" (without quotes)
RegExp
Example: before: "*Example", after: "*[[Example]]"
Find: "(\*)(.*)$" (without quotes)
Replace: "\1[[\2_(category)|\2]]" (without quotes)
RegExp
Example: before: "*Example", after: "*[[Example_(category)|Example]]"
Copyright © 2009 My Knowledges
Design by Design Disease for Smashing Magazine | Blogger Templates by Blog and Web