Ifedee Ifedee - 1 year ago 66
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

Answer Source

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

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

See live demo.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download