pretty simple regex replace help needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tgh003@gmail.com

    pretty simple regex replace help needed

    I need to replace a number in a string

    str = "http://www.example.com ?test=1&cat=0&r ef=123213123213 ";

    I want to replace the 0 after the cat= part with a new number. 0 could
    be any number though so i need to use a reg exp to replace it.

    str = str.replace(??? ???,newnumber);

    I need help with the ?????? part :>

    Any help is greatly appreciated.

    Thx!

  • moi

    #2
    Re: pretty simple regex replace help needed

    function reDemo() {
    var r = new RegExp(/=0/)
    var lnk = "http://www.example.com ?test=1&cat=0&r ef=123213123213 ";
    var newlnk = lnk.replace( r, "=123" );
    alert( newlnk );
    }



    <tgh003@gmail.c om> schreef in bericht
    news:1114397965 .687064.126720@ f14g2000cwb.goo glegroups.com.. .[color=blue]
    >I need to replace a number in a string
    >
    > str = "http://www.example.com ?test=1&cat=0&r ef=123213123213 ";
    >
    > I want to replace the 0 after the cat= part with a new number. 0 could
    > be any number though so i need to use a reg exp to replace it.
    >
    > str = str.replace(??? ???,newnumber);
    >
    > I need help with the ?????? part :>
    >
    > Any help is greatly appreciated.
    >
    > Thx!
    >[/color]


    Comment

    • Lee

      #3
      Re: pretty simple regex replace help needed

      tgh003@gmail.co m said:[color=blue]
      >
      >I need to replace a number in a string
      >
      >str = "http://www.example.com ?test=1&cat=0&r ef=123213123213 ";
      >
      >I want to replace the 0 after the cat= part with a new number. 0 could
      >be any number though so i need to use a reg exp to replace it.
      >
      >str = str.replace(??? ???,newnumber);
      >
      >I need help with the ?????? part :>[/color]

      str = str.replace(/cat=\d+/,"cat="+newnumb er);

      Comment

      Working...