|
-
Feb 2nd, 2001, 09:31 AM
#1
Thread Starter
Hyperactive Member
I am trying to parse a polynomial, so it could be of the form
1) 3-4x+5x^2
2) 3+5x^2-4x
3) 4x-3+5x^2
4) 4x+5x^2-3
5) 5x^2-3+4x
6) 5x^2+4x-3
Oh also there is the case that something is not there for example 3-4x so it will never find the x^2 coeffiecent, but match returns a null then so that is ok, cuz I can handle that later.
What I am doing is using the following: (on logs[1] is just the polynomial string)
c[0] = logs[1].match(/(\+|\-|^)(\d+)[^x]/);
c[1] = logs[1].match(/(\+|\-|^)(\d*)x[^^]/);
c[2] = logs[1].match(/(\+|\-|^)(\d*)x\^/);
Does anyone know why this doesnt work for all the above cases (1-6)?
Last edited by billrogers; Feb 2nd, 2001 at 09:37 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|