Search code examples
phpjavascriptstringscanf

Javascript equivalent of PHP's sscanf function?


Pretty basic question. I have a string, it will always be in the format of "(45.234235235,55.345345345)" with variable numbers of decimal places. I want to extract both of these numbers. In PHP I would sscanf, but I want to do this in Javascript.


Solution

  • There is nothing like sscanf, but you can use .replace() and .split():

    var data = str.replace(/[()\s]+/g, '').split(',');