【问题标题】:Get text between curly brackets in python在python中获取大括号之间的文本
【发布时间】:2015-04-22 14:10:22
【问题描述】:

我正在尝试从该文本的大括号中取出文本:

circle(265.17373,-53.674312,1") # text={1}
circle(265.17373,-53.674312,2") # text={2}

对于括号之间的东西,我使用这个并且那个有效

array = np.append(array, np.array([float(x) for x in re.findall(r"\d+(?:\.\d+)?", line)]))

但我也想要大括号内的文本。

array2 = np.append(array2, np.array([float(x) for x in re.findall(r"/\{([^}]+)\}/", line)]))

但这并没有回馈任何东西。

【问题讨论】:

  • \d+(?:\.\d+)? 也会给你{...}中的号码
  • “荣誉”是什么意思? en.wiktionary.org/wiki/accolade 如果您的意思是“花括号”或“花括号”,请注意它们在任何英语方言中都不称为“赞誉”。

标签: python regex findall


【解决方案1】:

您需要删除第二行代码中的正斜杠。

array2 = np.append(array2, np.array([float(x) for x in re.findall(r"\{([^}]+)\}", line)]

【讨论】:

    猜你喜欢
    • 2019-03-18
    • 1970-01-01
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-07
    • 2020-03-14
    • 1970-01-01
    相关资源
    最近更新 更多