mirror of
https://github.com/vladmandic/automatic
synced 2026-09-14 10:38:42 +02:00
15 lines
322 B
Python
15 lines
322 B
Python
import re
|
|
|
|
re_attention = re.compile(r"""
|
|
\(|\[|\\\(|\\\[|\\|\\\\|
|
|
:([+-]?[.\d]+)|
|
|
\)|\]|\\\)|\\\]|
|
|
[^\(\)\[\]:]+|
|
|
:
|
|
""", re.X)
|
|
|
|
texts = ["car:2.0", "(car:1.1)", "((car:1.2))", "[car:0.9]", "[[car:0.8]]"]
|
|
for text in texts:
|
|
for m in re_attention.finditer(text):
|
|
print(text, '0:', m.group(0), '1:', m.group(1))
|