M
M
Maxim Stikharev2018-02-05 12:48:13
Python
Maxim Stikharev, 2018-02-05 12:48:13

How to write a regular expression for a given Python string?

Line

Platform: Steam, id 1
  Avatar url:  randomurl.com
  Profile url: randomurl.com
  Signature url: randomurl.com
  Stats: {'wins': 145, 'goals': 772, 'mvps': 23, 'saves': 150, 'shots': 1214, 'assists': 42}
Ranked data: 
  Season 6: 
    Ranked season on playlist 10: SeasonPlaylistRank(rankPoints=529, division=3, matchesPlayed=88, tier=7)
    Ranked season on playlist 11: SeasonPlaylistRank(rankPoints=550, division=1, matchesPlayed=13, tier=8)
    Ranked season on playlist 12: SeasonPlaylistRank(rankPoints=430, division=2, matchesPlayed=17, tier=6)
The event loop has now exited after executing the example.

you need to take from here only the value inside the brackets (they are strings) and then how to present it in JSON format?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Segey K., 2018-02-05
@maximifn

import re

regex = re.compile(r'[{].+[}]')
res = regex.findall('Твоя строка в которой нужно найти подстроку')[0]

The resulting string can be converted to Json using
import ast

ast.literal_eval(res)

5a782ecbaa5ab717142191.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question