Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Location
    Northbrook, IL
    Posts
    394
    Thanks
    8
    Thanked 6 Times in 6 Posts

    Question split() with regexp in FF2 returns an array including delimiters?

    Code:
    var myString = "hello0x0there";
    splitString = string.split(/(0x0){1}/);
    in firefox the returned array is 3 elements long, with the middle one being the actual 0x0.

    is this the intended implementation, and why?

    Leon

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    the ()s in the regexp mean it will 'capture', to exclude the delimiter, you would want to use:
    Code:
    splitString = string.split(/(?:0x0){1}/);
    The ?: makes the bracketed group 'non-capturing'. In the example you've given, then grouping with {1} isn't needed though, so you could just use
    Code:
    splitString = string.split(/0x0/);
    or do away with RE all together, and use:
    Code:
    splitString = string.split('0x0');
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com


  •  

    Posting Permissions

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