
March 29, 2022
8 a.m.
28.03.22 15:13, StrikerOmega пише:
And I want to grab some kind of value from it.
There is a powerful tool designed for solving such problems. Is is called regular expressions.
sample.grab(start="fruit:", end="\n")
'apple'
re.search(r'fruit:(.*?)\n', sample)[1]
sample.grab(start="tree:[", end="]")
'Apple tree'
re.search(r'tree:\[(.*?)\]', sample)[1]
sample.grab(start="quantity:{", end="}", list_out=True)
[5, 3]
list(re.findall(r'quantity:\{(.*?)\}', sample))