search

Home  >  Q&A  >  body text

mysql - 用Python怎么在一个字符串里面取到想要的数据?

从数据库中提取到一个字符串。
a:2:{i:27;a:6:{s:3:"did";i:27;s:3:"num";i:1;s:8:"discount";s:1:"0";s:5:"price";s:2:"40";s:4:"name";s:12:"芒果雪冰";s:5:"omark";s:0:"";}i:36;a:6:{s:3:"did";i:36;s:3:"num";i:1;s:8:"discount";s:1:"0";s:5:"price";s:2:"40";s:4:"name";s:12:"抹茶雪冰";s:5:"omark";s:0:"";}}

现在要取出其中的“芒果雪冰”跟“抹茶雪冰”,用什么方法呢。。

高洛峰高洛峰2896 days ago1099

reply all(4)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:15:59

    Isn’t this the result of PHP serialization? Regular expressions are the best for python

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:15:59

    Use regular expressions to match strings preceded by "s:12:" and followed by quotes.

    import re
    match_list = re.findall('(?<=s\:12\:)\".+?\"', s1)
    

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:15:59

    It is not recommended that you use regular expressions to extract. For regular data, the best way is to use the corresponding parsing format, which is json. It is recommended that you use json to parse directly, of course, if you need it. You can use it directly to extract Chinese.

    ^[u4E00-u9FA5]+$

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:15:59

    This is the serialization of PHP variables. There is a third-party module in Python called phpserialize that can convert it to Python data types. Specific tutorials can be found here:
    Python uses PHP serialized data

    If possible, please extract it yourself. Okay?

    reply
    0
  • Cancelreply