Popular recipes tagged "replace" but not "regex"http://code.activestate.com/recipes/tags/replace-regex/2015-09-16T16:25:49-07:00ActiveState Code Recipesgenerates a set of binary files by doing ASCII replacements on a master binary file, controlled by a csv file (Python)
2015-09-16T16:25:49-07:00Antoni Gualhttp://code.activestate.com/recipes/users/4182514/http://code.activestate.com/recipes/579099-generates-a-set-of-binary-files-by-doing-ascii-rep/
<p style="color: grey">
Python
recipe 579099
by <a href="/recipes/users/4182514/">Antoni Gual</a>
(<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/replace/">replace</a>).
</p>
<p>A hack that saved me a lot of time. Well perhaps not so much, but it was funnier than to do it manually. </p>
Recursive find and replace in all files in directory with regex (Python)
2013-03-21T12:33:44-07:00ccpizzahttp://code.activestate.com/recipes/users/4170754/http://code.activestate.com/recipes/578312-recursive-find-and-replace-in-all-files-in-directo/
<p style="color: grey">
Python
recipe 578312
by <a href="/recipes/users/4170754/">ccpizza</a>
(<a href="/recipes/tags/directory/">directory</a>, <a href="/recipes/tags/recursion/">recursion</a>, <a href="/recipes/tags/regular_expressions/">regular_expressions</a>, <a href="/recipes/tags/replace/">replace</a>).
</p>
<p>Search and replace files recursively in a given directory. Accepts regular expressions as search and replacement patterns.</p>
<p><strong>Example usage</strong>:</p>
<pre class="prettyprint"><code>python find_replace_regex.py ".", "<span[^>]*>", "<div>", "*.html" backup
</code></pre>
<p><strong>Note</strong>:
On win32 the <code><</code> and <code>></code> symbols are interpreted by the shell as input/output redirection even when they are surrounded with single or double quotes, and therefore need to be escaped with the caret character <code>^</code>.</p>
Context manager to atomically replace a file (Python)
2012-06-17T12:09:49-07:00Oren Tiroshhttp://code.activestate.com/recipes/users/2033964/http://code.activestate.com/recipes/578166-context-manager-to-atomically-replace-a-file/
<p style="color: grey">
Python
recipe 578166
by <a href="/recipes/users/2033964/">Oren Tirosh</a>
(<a href="/recipes/tags/atomic/">atomic</a>, <a href="/recipes/tags/contextmanager/">contextmanager</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/replace/">replace</a>).
Revision 3.
</p>
<p>This context manager ensures that a file's content is either replaced atomically with new contents or left unchanged. An exception or other error will not leave it empty or with partial content.</p>
For Characters in a String, Replace with Character (Python)
2012-03-23T20:44:23-07:00Andrew Yurisichhttp://code.activestate.com/recipes/users/4180867/http://code.activestate.com/recipes/578086-for-characters-in-a-string-replace-with-character/
<p style="color: grey">
Python
recipe 578086
by <a href="/recipes/users/4180867/">Andrew Yurisich</a>
(<a href="/recipes/tags/character/">character</a>, <a href="/recipes/tags/replace/">replace</a>, <a href="/recipes/tags/substitute/">substitute</a>, <a href="/recipes/tags/text/">text</a>).
Revision 9.
</p>
<p>Useful if you need to replace many different characters with all of the same character. Can accept an unlimited number of request to replace.</p>
<p>Does not work with words, only characters. You can, however, replace single characters with words. I may go back and re-implement it using tuples for the keys, but this would make searching the text for any matches pretty expensive, I'd imagine. At that point, it's mostly a job for a regex, and those tools already exist.</p>
C# String.Replace with a char array (Java)
2010-12-24T09:58:35-08:00John Hurlimanhttp://code.activestate.com/recipes/users/4174599/http://code.activestate.com/recipes/577516-c-stringreplace-with-a-char-array/
<p style="color: grey">
Java
recipe 577516
by <a href="/recipes/users/4174599/">John Hurliman</a>
(<a href="/recipes/tags/csharp/">csharp</a>, <a href="/recipes/tags/replace/">replace</a>, <a href="/recipes/tags/string/">string</a>).
</p>
<p>Takes a string and replaces all characters matching a given array with a given string</p>
Improved range function (Python)
2010-06-07T01:50:20-07:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577256-improved-range-function/
<p style="color: grey">
Python
recipe 577256
by <a href="/recipes/users/4174115/">Sunjay Varma</a>
(<a href="/recipes/tags/float/">float</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/range/">range</a>, <a href="/recipes/tags/replace/">replace</a>).
Revision 2.
</p>
<p>While using the built-in range function a while ago. I found an odd (perhaps bug) where the range function couldn't use float steps. I am not sure if that was intended for simplicity or not, but I wrote my own range function that goes beyond that anyway.</p>
REAL case insensitive string replace (Python)
2009-04-25T15:48:50-07:00Jonas Haaghttp://code.activestate.com/recipes/users/4169206/http://code.activestate.com/recipes/576715-real-case-insensitive-string-replace/
<p style="color: grey">
Python
recipe 576715
by <a href="/recipes/users/4169206/">Jonas Haag</a>
(<a href="/recipes/tags/case/">case</a>, <a href="/recipes/tags/case_insensitive/">case_insensitive</a>, <a href="/recipes/tags/replace/">replace</a>, <a href="/recipes/tags/str/">str</a>).
Revision 2.
</p>
<p>REAL case insensitive version of <code>str.replace</code> that keeps the letter case of the original expression (Doesn't only replace <code>Foo</code> and <code>foo</code> to <code>...foo...</code> but to <code>...Foo..</code> and <code>...foo...</code>).</p>