[英]regex to extract data between quotes
As title says string is '="24digit number"'
and I want to extract number between ""
(example: ="000021484123647598423458"
should get me '000021484123647598423458'
). 如标题所示,字符串为
'="24digit number"'
,我想提取""
之间的数字(例如: ="000021484123647598423458"
应该使我为'000021484123647598423458'
)。
There are answers that answer how to get data between "
but in my case I also need to confirm that ="
exist without capturing (there are also other "\\d{24}"
strings, but they are for other stuff) it. 有一些答案可以回答如何在
"
之间获取数据"
但就我而言,我还需要确认="
存在而没有捕获(还有其他"\\d{24}"
字符串,但它们用于其他用途)”。
I couldn't modify these answers to get what I need. 我无法修改这些答案来获得所需的信息。
My latest regex was ((?<=\\")\\d{24}(?=\\"))
and string is ="000021484123647598423458"
. 我最新的正则表达式为
((?<=\\")\\d{24}(?=\\"))
,字符串为="000021484123647598423458"
。
UPDATE: I think I will settle with pattern r'^(?:\\=\\")(\\d{24})(?:\\")'
because I just want to capture digit characters. 更新:我想我会使用模式
r'^(?:\\=\\")(\\d{24})(?:\\")'
因为我只想捕获数字字符。
word = '="000021484123647598423458"' pattern = r'^(?:\\=\\")(\\d{24})(?:\\")' match = re.findall(pattern, word)[0]
Thank you all for suggestions. 谢谢大家的建议。
You could have it like: 您可以像这样:
=(['"])(\d{24})\1
See a demo on regex101.com . 参见regex101.com上的演示 。
Python
:
Python
:
import re string = '="000021484123647598423458"' rx = re.compile(r'''=(['"])(\\d{24})\\1''') print(rx.search(string).group(2)) # 000021484123647598423458
Any one of the following works: 以下任何一项作品:
>>> st = '="000021484123647598423458"'
>>> import re
>>> re.findall(r'".*\d+.*"',st)
['"000021484123647598423458"']
or 要么
>>> re.findall(r'".*\d{24}.*"',st)
['"000021484123647598423458"']
or 要么
>>> re.findall(r'"\d{24}"',st)
['"000021484123647598423458"']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.