程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How Python uses regular matching to match numbers after strings

編輯:Python
text='AND(AA6<AI6,AG7>BA10)' # original text # Replace dictionary list = { "AA":" Xiao Ming ","AG":" Xiao Wang ",}# We hope to achieve the following results text_new='AND( Xiao Ming <AI6, Xiao Wang >BA10)' # Exact match only , It is impossible to put Xiao Ming , The number after Xiao Wang is replaced by for item in list: text_new = score_formula.replace(item,list[item])#text_new='AND( Xiao Ming 6<AI6, Xiao Wang 7>BA10)'# I try to write regular , But it failed for item in list: reg=re.compile(list[item] +"d+") match=reg.search(text)

How to optimize ??


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved