Str_Replace(Str, Find, Replace, Flags)

Code

    Str_Replace = function(Str, Find, Replace, Flags) {
        /*
        Purpose
            Used to replace a specified string with another string.
        Parameters
            Str (string) = The string were operating on.
            Find (string) = The string we're searching for.
            Replace (string) = The string we're replacing Find with.
            Flags (optional string) = Determines how the replace is performed.
                This is a character string that is sent to the RegExp(Flags) parameter.
                Some valid valids:
                    "g" Perform a global replace. All instances of Find are replaced.
                    "i" Perform a case-insensitive replace.
                Default if falsey: "g"
        Return (string)
            Returns a string with Find replaced with Replace.
        Version History
            1.0 2015.12.06 Tested by Russ Tanner.
        */

        // Default parameters
        Flags = Flags || 'g';

        // Escape the Find string so any special characters can be used.
        FindEscaped = Find.replace(/[-[\]{}()*+!<=:?.\/\\^$|#\s,]/g, '\\$&');

        // Perform the replacement and return the result.
        var re = new RegExp(FindEscaped, Flags);
        return Str.replace(re, Replace);

    }

Last edited by Russ; 12/06/15 08:44 PM.

The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)