正则表达式仅匹配出现重复匹配的一种情况?

时间:2020-03-06 00:49:19

标签: python regex python-3.x data-cleaning

[PYTHON 3.7]

  • 使用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作为进行正则表达式的参考。

对于解决方案的任何建议或“更好的实践”将不胜感激。

0 个答案:

没有答案