/    Sign up×
Community /Pin to ProfileBookmark

replace function problem

hi,
i wanna replace ‘[5]’ with ‘[6]’ (numbers are not important) i use

htmlCode=<input type=”text” name=”bbDetail[5].msisdn” id=”bbDetail[5].msisdn” class=”numericData” disabled=”true” size=”20″ value=”5322100191″ >
regex=/[5]/g;
var newHtml=htmlCode.replace(regex,'[6]’);

but result is
newHtml=htmlCode=<input type=”text” name=”bbDetail[[6]].msisdn” id=”bbDetail[[6]].msisdn” class=”numericData” disabled=”true” size=”20″ value=”[6]322100191″ >

if i use like that
var newHtml=htmlCode.replace(regex,'[6]’);
htmlCode=<input type=”text” name=”bbDetail[6].msisdn” id=”bbDetail[6].msisdn” class=”numericData” disabled=”true” size=”20″ value=”6322100191″ >

it changes ‘5’ to ‘6’ not only ‘[5]’

but i want

htmlCode=<input type=”text” name=”bbDetail[6].msisdn” id=”bbDetail[6].msisdn” class=”numericData” disabled=”true” size=”20″ value=”5322100191″ >

where am i wrong?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangJan 04.2006 — The brackets must be escaped:regex=/[5]/g;
Copy linkTweet thisAlerts:
@pornovaauthorJan 04.2006 — i solve problem with another way

contents=contents.split("["+lastRow+"]");

contents=contents.join("["+newRowNumber+"]");

thanks
×

Success!

Help @pornova spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...