我正在尝试使用正则表达式或python函数来提取所有粗体文本,或介于“和<;=”之间的文本
"[Text(447.1153846153846, 471.625, 'the <= 0.5\nentropy = 0.97\nsamples = 100.0%\nvalue = [0.399, 0.601]\nclass = True News'), Text(238.46153846153845, 336.875, 'donald <= 0.5\nentropy = 0.921\nsamples = 83.7%\nvalue = [0.336, 0.664]\nclass = True News'), Text(119.23076923076923, 202.125, 'hillary <= 0.5\nentropy = 0.981\nsamples = 55.6%\nvalue = [0.42, 0.58]\nclass = True News'), Text(59.61538461538461, 67.375, '\n (...) \n'), Text(178.84615384615384, 67.375, '\n (...) \n'), Text(357.6923076923077, 202.125, 'hillary <= 0.5\nentropy = 0.663\nsamples = 28.2%\nvalue = [0.172, 0.828]\nclass = True News'), Text(298.0769230769231, 67.375, '\n (...) \n'), Text(417.30769230769226, 67.375, '\n (...) \n'), Text(655.7692307692307, 336.875, 'trumps <= 0.5\nentropy = 0.859\nsamples = 16.3%\nvalue = [0.718, 0.282]\nclass = Fake News'), Text(596.1538461538462, 202.125, 'hillary <= 0.5\nentropy = 0.821\nsamples = 15.7%\nvalue = [0.744, 0.256]\nclass = Fake News'), Text(536.5384615384615, 67.375, '\n (...) \n'), Text(655.7692307692307, 67.375, '\n (...) \n'), Text(715.3846153846154, 202.125, 'entropy = 0.0\nsamples = 0.6%\nvalue = [0.0, 1.0]\nclass = True News')]"
到目前为止,我得到的最接近的是(?=')(*)(?=<;=),但到目前为止没有运气
有人能告诉我如何在单引号和<;=之间提取这些粗体文本吗
不需要使用正则表达式
谢谢
这个正则表达式有效。我们使用命名组,因此很容易引用所需的确切数据。它的设置是查找连续的单词和后跟“<;=”的数字。然后我们使用
finditer
获得所有匹配项如果您只想看整个9码,下面将把整个内容解析成一个命名元组,它主要反映文本的格式。我不知道前两个值代表什么,所以我只称它们为
x
和y
。我这么做是因为你想要的似乎不是很有用,我认为这个问题只是最终确定更多数据的前兆。这将精确定位所有数据。任何带有\n (...) \n
数据的条目都被打印为“空”,并且不存储在条目list
中使用单引号
'
的后向查找和<=
中间的非引号字符可以与内容匹配
https://regex101.com/r/KlYLQ2/1
一种方法:
输出
相关问题 更多 >
编程相关推荐