简体   繁体   English

在正则表达式中排除组

[英]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我想使用正则表达式匹配某个数字的幂值:示例: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".目前此代码将返回“^2”而不是“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) + ")"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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