0

i need to get number with sign from a string.

eg:

-675.5+987.5i
+675.5-987.5i 

output:

-675.5

+987.5

+675.5

-987.5
1
  • 1
    Accept your recent questions.
    – hsz
    Commented Apr 5, 2011 at 8:55

1 Answer 1

3
var numbers = "-675-987i".match(/[-+]\d+(\.\d+)?/g);

Edited to handle also plus sing and float value.

4
  • var number ="-675.5-987.7i" ---> output=-675.5,-987.7
    – Tarun
    Commented Apr 5, 2011 at 9:02
  • It returns an array - just handle it as an array :)
    – hsz
    Commented Apr 5, 2011 at 9:41
  • var number=this.match(/(-|\+)?\d+\.?\d*/g) get the output thanks a lot
    – Tarun
    Commented Apr 5, 2011 at 10:03
  • 1
    @Tarun if this was what you're after please click the "V" icon to the left to Accept this answer as correct. If for your own reasons you insist on not doing so it's your choice but people will simply stop helping you in this place. Commented Apr 5, 2011 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.