javascript - content replace function -
i have follow question content replace function:
this current content replace function:
content = content.replace(/(<t t>(.*?)<t t>)/g, function(m,p1,p2){ homecoming p2,p1.replace(/ /g,"_").replace(/<t t>/g,"<html>"); });
when run:
this <t t>this test<t t> of
through html process text area:
<textarea id="content" cols="48" rows="8"></textarea><br /> <input type="button" value="process" onclick="process()" />
i receive output:
this <t_t>this_a_test<t_t> of replace.
rather want this:
this <t d>this_a_test<t d> of replace.
i know reason
<t t>
does not replace with
<t d>
is because function looking space , in turn omit space , create underscore. cannot figure out how not have happen, whilst still replacing space underscore within 2 tags, e.g.
this test
will become
this_a_test
the answerer previous question used useful resource .replace() method help me understand, much chagrin not figure out myself. give thanks much ahead of time help, if need here link example
so, according comment...
...so when "this <t t>this test<t t> of replace". entered in process text area result "this <t d>this_a_test<t d> of replace"...
... can do:
content.replace(/<t t>/g, "<t d>");
keep in mind /g
flag in regular expressions matches patterns in tested string (g stands "global").
javascript replace
No comments:
Post a Comment