re
模块这是我的re.search
字符串:
'(?<=Access {)[\w\W]+(?=~Access)'
我也尝试过:
'Access[\w\W]+Access'
我的测试字符串:
4 : {'IsMissing': 'false', 'Name': 'Trans7', 'Number': '7', 'ProgrammingLanguage': 'LAD'}~FlgNet {}~Parts {}~Access {'Scope': 'LocalVariable', 'UId': '21'}~Symbol {}~Component {'Name': 'DATA'}~Component {'Name': 'sOFF'}~Access {'Scope': 'LocalVariable', 'UId': '22'}~Symbol {}~Component {'Name': 'Me'}~Component {'Name': 'SEQ03'}~Component {'Name': 'sRUN'}~Part {'Name': 'Contact', 'UId': '23'}~Part {'Name': 'Contact', 'UId': '24'}~Negated {'Name': 'operand'}~Part {'Name': 'TrCoil', 'UId': '25'}~Wires {}~Wire {'UId': '26'}~Powerrail {}~NameCon {'UId': '23', 'Name': 'in'}~Wire {'UId': '27'}~IdentCon {'UId': '21'}~NameCon {'UId': '23', 'Name': 'operand'}~Wire {'UId': '28'}~NameCon {'UId': '23', 'Name': 'out'}~NameCon {'UId': '24', 'Name': 'in'}~Wire {'UId': '29'}~IdentCon {'UId': '22'}~NameCon {'UId': '24', 'Name': 'operand'}~Wire {'UId': '30'}~NameCon {'UId': '24', 'Name': 'out'}~NameCon {'UId': '25', 'Name': 'in'}~
我只能得到 1
个匹配项:
Access {'Scope': 'LocalVariable', 'UId': '21'}~Symbol {}~Component {'Name': 'DATA'}~Component {'Name': 'sOFF'}~Access
我已经在Pythex中进行过测试。
我一直使用re Python Documentation作为进行正则表达式的参考。
对于解决方案的任何建议或“更好的实践”将不胜感激。