SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Jan 25, 2007, 02:39 #1
- Join Date
- Jan 2007
- Posts
- 15
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Search and replace a defenite string
Hi..
I having trouble in search and replace a specific string
;) -- replace with "wink"
;;) --reblace with "DBL_wink"
When i give in my Js file
mytext = mytext.replace(/\;\)/ig,"wink")
mytext = mytext.replace(/\;;\)/ig,"DBL_wink")
The output is
;) -- is REPLACED with "wink" ---correct
;;)-- is REPLACED with " ;wink" --not correct (must be "DBL_wink")
Waht am i missing here
Can anyone help me please
Deepa
-
Jan 25, 2007, 02:51 #2
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Call the second one first, since the first one is a subset:
Code:mytext = mytext.replace(/;;)/g, "DBL_wink"); mytext = mytext.replace(/;)/g, "wink");
to "wink". That means that any occurrence of ;;
will be changed into ";wink" by the first replace. There will be no occurrence of ;;
left for the second replace.
Birnam wood is come to Dunsinane
-
Jan 25, 2007, 02:53 #3
- Join Date
- Jan 2007
- Posts
- 15
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
that was pretty quick.thanks. let me try
-
Jan 25, 2007, 02:54 #4
- Join Date
- Jan 2007
- Posts
- 15
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
wow.. worked like a charm..
thanks
Bookmarks