Replacing multiple patterns in a block of data
Posted
by VikrantY
on Stack Overflow
See other posts from Stack Overflow
or by VikrantY
Published on 2010-03-23T15:56:34Z
Indexed on
2010/03/23
23:43 UTC
Read the original article
Hit count: 271
Hi All,
I need to find the most efficient way of matching multiple regular expressions on a single block of text. To give an example of what I need, consider a block of text:
"Hello World what a beautiful day"
I want to replace Hello with "Bye" and "World" with Universe. I can always do this in a loop ofcourse, using something like String.replace functions availiable in various languages.
However, I could have a huge block of text with multiple string patterns, that I need to match and replace.
I was wondering if I can use Regular Expressions to do this efficiently or do I have to use a Parser like LALR.
I need to do this in JavaScript, so if anyone knows tools that can get it done, it would be appreciated.
© Stack Overflow or respective owner