SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    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

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    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");
    What happens is that your first call changes all occurrences of &#59 to "wink". That means that any occurrence of ;&#59 will be changed into ";wink" by the first replace. There will be no occurrence of ;&#59 left for the second replace.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that was pretty quick.thanks. let me try

  4. #4
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow.. worked like a charm..
    thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •