Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Problem with writing a Regex expression in javascript

Last post 06-28-2008, 2:01 AM by mash. 1 replies.
Sort Posts: Previous Next
  •  06-28-2008, 12:59 AM 43557

    Problem with writing a Regex expression in javascript

    Hi

    I am trying to write a regular expression in javascript but I am having a hard time getting it to work. 

    I am returning data from my c# server that comes back like this:

    ggga,12&4,4&ggg,234&

     Now there are 2 fileds the name field and the repetitions. each fold these fields is seperated by the comma. Each group is then seperated by the & symbol.

    So the results should be

     ggga,12

    4,4

     ggg,234

    Then later I want to seperate it further since I will then need each indivdual field(maybe use capturing parenthesis? So I would have one to capture the names and one to capture the repetitions).

     Now I written some regular expression in C# so I used a program called "expresso" but it is more for the .net framework. In it I wrote this

    ([a-z0-9]+),([0-9]+)

    My results

    ggga,12
    4,4
    ggg,234

    Exactly what I wanted.

     But in Javascript I get a different story. I used the same expression and got:

    ggga,12
    ggga
    12

    Not what I wanted. So what am I doing wrong?

     Thanks

    Here is my javascript code:

    var strip = /([a-z0-9]+),([0-9]+)/i;

      var result = strip.exec(response);

     where response contains(ggga,12&4,4&ggg,234&).

     

     

  •  06-28-2008, 2:01 AM 43559 in reply to 43557

    Re: Problem with writing a Regex expression in javascript

    Add the global option to your regex to return all the matches instead of the first one

    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
View as RSS news feed in XML