【发布时间】:2020-09-09 20:15:11
【问题描述】:
我开始学习 Python,现在才开始学习正则表达式。我想弄清楚搜索字符串以找到始终直接跟随某个子字符串的数字(可以是不同长度)的最佳方法是什么。
例如:
string = """ this is a very long string with 495834 other numbers;
if I had the ( 5439583409 );
Keyword_indicator( 53029453 ); //
energy to type more and more; ..."""
我希望能够在字符串中搜索仅显示在此处的“Keyword_indicator”,然后在括号内拉出数字,知道该数字不是设定的长度。
output = "53029453"
编辑 - 字符串中包含其他数字,而我要查找的数字始终是整数。
【问题讨论】:
-
您的号码始终是无符号整数?
-
你试过实现这个吗?
-
这能回答你的问题吗? Get only numbers from string in python