Hi Monks,
How are you doing today? I am in a little trouble and need your help with regex.
I am replacing some strings in JavaScript. However, I believe the same regex will work for both JavaScript and Perl.
With my method of replacing, I am getting into the problem of recursive replacement.
I want to do the following.
1. Replace & with &
2. Replace &lt; with <
3. Replace &gt; with >
4. Replace < with <
5. Replace > with >
I tried to include the following code snippets in my JS code.
But the problem with the above code snippet is, both text segments like [<] and [&lt;] will be replaced ultimately with [<] symbol. Is it possible to include all the three replacements in a single statement to avoid recursive replacement?new_json_string = new_json_string.replace(/&/g, '&'); new_json_string = new_json_string.replace(/</g, '<'); new_json_string = new_json_string.replace(/>/g, '>');
In reply to Avoid recursive replacement using regex by anirudhkumar_r
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |