简体   繁体   中英

Exclude group in Regex expression

I would like to match the power value of a certain number using Regex: Exemple: A^2 --> num_pow = 2

power = "(\^[+-]?[1-9]\d*)"
num_pow1 = "(?P<num_pow1>" + power + ")"
num_pow2 = "(?P<num_pow2>" + power + ")"

currently this code will return "^2" rather than "2". I tried using "?:" without any sucess.

power = "\^([+-]?[1-9]\d*)"
num_pow1 = "(?P<num_pow1>" + power.group(1) + ")"
num_pow2 = "(?P<num_pow2>" + power.group(1) + ")"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM