Unicode字符的正则表达式

2024-09-29 03:35:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在Python代码中使用regex来匹配“★★★★★★☆”。这是游戏商店的东西。你知道吗

  • 如果我得到★★★★☆★★★★★★★★★★★或★★★★★★★★★★★★★我需要打印为“高票” 以及
  • 如果我得到★☆☆☆或★★☆☆☆我需要打印“低评级”

我的代码是这样的:

   if re.search(ur'[\u2605\u2605\u2605\u2606\u2606]+', d) \
    or re.search(ur'[\u2605\u2605\u2605\u2605\u2606]+', d)\
    or re.search(ur'[\u2605\u2605\u2605\u2605\u2605]+', d):
       print "High rated playstore tickets"

   if re.search(u'[\u2605\u2605\u2606\\u2606\u2606]+',d) \
    or re.search(u'[\\u2605\\u2606\\u2606\\u2606\\u2606]+',d):

       print "Low rated tickets"

不能特别配对。 请帮忙


Tags: or代码re游戏searchifratedregex