Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道这是一个非常简单的正则表达式问题,但我仍然无法匹配它。
需要匹配的字符串是"10K-50K"
"10K-50K"
我想使用正则表达式从字符串中提取 10 和 50。
In [6]: data = "10K-50K" In [7]: data1 = re.match(r'([\d][A-Z])-([\d][A-Z])',data)
但是,它总是返回一个Nonetype.
Nonetype
我对正则表达式语法感到困惑,希望有人可以帮助我。
尝试这样的事情:
import re data = "10K-50K" str_tokens = re.match(r'([0-9]*)[a-zA-Z]-([0-9]*)[a-zA-Z]', data).groups() int_tokens = [int(token) for token in str_tokens] print(str_tokens, int_tokens)
输出:
('10', '50') [10, 50]