gpt4 book ai didi

python - 任何带有字符串(字母和标点符号)的数字的正则表达式是什么?

转载 作者:太空宇宙 更新时间:2023-11-03 15:51:08 24 4
gpt4 key购买 nike

<分区>

我有以下文字:

输入:

mandatory NORMAL
P1000 NONE
of NONE
coastal NONE
35 NONE
was NONE
ordered
. NONE
With NORMAL
the NONE
typhoon
out NONE
of NONE
the NONE
country NORMAL
local NORMAL
governments
1000,000 NORMAL

我正在使用以下代码提取包含数字的单词(例如 $1001000.0041AV909() -O87 等)NUMBER 关键字替换包含数字的单词之后的任何单词:

def tag_words(input):
numbers = re.findall(r"\d+", input)
tagged_text = st.tag(per_word(input))
string_type = '\n'.join(' '.join(line) for line in tagged_text)
filtered_text = re.sub(r"\bNONE(?=\n|$)", "NONE", string_type)
return filtered_text

我已经尝试过不同的模式,但没有一个返回预期的输出:

输出:

mandatory NORMAL
P1000 NUMBER
of NONE
coastal NONE
35 NUMBER
was NONE
ordered
. NONE
With NORMAL
the NONE
typhoon
out NONE
of NONE
the NONE
country NORMAL
local NORMAL
governments
1000,000 NUMBER

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com