String Multi Replace: Replace multiple expressions in a single string

Recommend this page to a friend!
     
  Info   Example   View files Files   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 113 All time: 396 This week: 4Up
Version License JavaScript version Categories
str_multi_replace 1.0BSD License1.0Text processing
Description 

Author

This package replace multiple expressions in a single string.

It alters the string replace prototype function to allow the regular expression parameters to be a set of regular expression objects, so the function will search and replace for all the specified expressions.

The replacement text may be either a single string or also a set texts that will replace the corresponding matching regular expression.

Innovation Award
JavaScript Programming Innovation award nominee
September 2015
Number 2


Prize: One book of choice by Packt
In JavaScript it is possible to change values in string replacing marks or regular expressions by replacement values.

If you want to perform multiple types of replacements you need to call the replace function multiple types.

This package changes the string object prototype function to allow replacing an array of expressions in a single call.

Manuel Lemos
Picture of Martin Barker
  Performance   Level  
Name: Martin Barker <contact>
Classes: 10 packages by
Country: United Kingdom
Innovation award
Innovation award
Nominee: 6x

Winner: 4x

Example

// setup a stirng var test = "hello world"; // this shows that the original String.replace method still works var original = test.replace("world","martin"); // original == "hello martin"; // this replaces based on index to array1[0] will become array2[0] var newStr = test.replace(["hello", "world"], ["bye", "martin"]); // newStr == "bye martin" // this replaces all first values with the second value var newStr2 = test.replace(["hello", "world"], "bye"); // newStr2 == "bye bye";

  Files folder image Files (2)  
File Role Description
Accessible without login Plain text file Demo.js Example example of how to use.
Plain text file StringReplace.js Class Main File

 Version Control Unique User Downloads Download Rankings  
 0%
Total:113
This week:0
All time:396
This week:4Up