我有一个字符串,比如:
Location: FD130 New York GA Unit Serial Purchase Order Sales Order Make Model Amount Tax Total 12345566 Location: FD130 Roswell GA Unit Serial Purchase Order Sales Order Make Model Amount Tax Total 0130029964
当我尝试regex时,喜欢获取指定序列号(34573(的位置。Regex:'Location:(.*)?Unit(.*?)0130029964
然后它给出了整个字符串的位置,并以34573结束。
当我通过0130029964
序列id时,预期输出为FD130 New York GA
。
python中有没有从给定的序列号中获取第一个向后子字符串location
的函数
您可以使用调和贪婪令牌方法在unit
的第一次出现时匹配位置单元,以不交叉匹配location:
unit
或format
。
然后可选地匹配format
并匹配到特定数字,而不必再次交叉匹配location:
。
blocation:s*((?:(?!location:|unit|format).)+) (?:format )?unit (?:(?!location:).)+b12345566b
Regex演示