Link to home
Start Free TrialLog in
Avatar of NevSoFly
NevSoFly

asked on

Need help matching and solving for numbers with exponents.

I am looking for a pattern to match numbers from an expression that have exponents and are enclosed in ():
(64²xy)                                should match 64²
(6xy/-2²³xy)                        should match -2²³
(64²xy/2²yx)                       should match 64² and 2²
(6xy/-2²³+ab)                     should match -2²³
6xy/-2²³xy                          should not match anything as the expression is not enclosed in ()

The closest I have come to solving this is "([\-]?[0-9]+[°¹²³]+)".  This pattern matches all of the above example text but I only want it to match the first four examples.

Finally I would like to replace the matched text with a number that solves the exponent.
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NevSoFly
NevSoFly

ASKER

I tested your suggestion on gskinner.com/regexr but it didn't return any matches.
I tried it myself; the copy and paste of the pattern added a space character to the end, which broke it. Once I removed the space, it worked.
User generated imageAlso, in case it helps anyone else, the correct URL for the site's online tool is http://gskinner.com/RegExr/
Thanks, deleting that extra space made all the difference in the world.
Sorry, I forgot about the second part of my question.   I would like to replace the matched text with a number that solves the exponent.
My specialty is regular expressions (I don't program in .NET) so you're probably best asking a separate question if you need help with that.