inherit
125499
0
Nov 8, 2011 4:03:57 GMT -8
moneyman18
:-
952
June 2008
moneyman18
|
Post by moneyman18 on Nov 17, 2009 19:16:12 GMT -8
Ok I need some help with this.
<html> <head> </head> <body>
<font size="2"> abcdefghijklmnopqrstuvwxyz [test:2425,400,400] </font>
<script type="text/javascript"><!-- var mFont = document.getElementsByTagName('font'); for(i=0;i<mFont.length;i++){ if(mFont.item(i).innerHTML.match(/\[test\:(\d+)(,(\d+))?(,(\d+))?\]/)){ var pattern = new RegExp('[test:'+RegExp.$1+RegExp.$2+RegExp.$4+']', 'g'); var replacement = '123'; mFont.item(i).innerHTML = mFont.item(i).innerHTML.replace(pattern, replacement); } } //--></script>
</body> </html>
Im obviously doing something wrong as this is the result I get:
abcd123fghijklmnopqr123123uvwxyz [123123123123123123123123123123123123123123123123123]
pattern turns out to be from this:
/[test:2425,400,400]/g
All I am trying to do is replace [test:2425,400,400] once with replacement variable. I should only have 123 once but instead I get it a bunch. Any clues what I am doing wrong?
|
|
inherit
100824
0
May 13, 2012 5:37:49 GMT -8
Michael
14,585
March 2007
wrighty
|
Post by Michael on Nov 17, 2009 19:25:03 GMT -8
Why are you defining the pattern? Why not use the exacy same as your match statement? O.o
|
|
inherit
125499
0
Nov 8, 2011 4:03:57 GMT -8
moneyman18
:-
952
June 2008
moneyman18
|
Post by moneyman18 on Nov 17, 2009 19:35:56 GMT -8
Because I did not think of doing that. I'll change it later on as I'm just bout to get off the computer.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Nov 17, 2009 22:08:44 GMT -8
[test:whatever] is in brackets, which means "any of these characters," so it's replacing anything in those brackets with 123.
Use \[test:regex-stuff\] Escaping the brackets will check them as character brackets instead of RegEx brackets.
|
|
inherit
125499
0
Nov 8, 2011 4:03:57 GMT -8
moneyman18
:-
952
June 2008
moneyman18
|
Post by moneyman18 on Nov 18, 2009 5:27:58 GMT -8
o.O I did not even realize that.
I thought since it was in the quotes within the new RegExp() that you did not need backslashes. I shouldv'e known.
Thanks so much for your help!
|
|