Ifedee Ifedee - 3 months ago 12
Perl Question

How can I extract variables with nonzero coefficients from an equation using a Perl regex?

I wish to grab the non-zero coefficients of a particular number arrangement. I have the set of numbers below and I wish to strictly extract with regex the non-zero coefficient (

) from

x1 *0.000000+ x2 *-0.100000+ x3 *0.850000+ x4 *0.000000+ x5 *0.000056+ x6 *0.000000

I tried doing this


but am not really sure as to declare that it shouldn't consider the


Match x-digit not followed by space-star-zero-dot-zeroes-endOfWord:

x\d+(?! \*0\.0+\b)

See live demo.