移除支架之间的任何东西

2024-09-30 06:14:35 发布

您现在位置:Python中文网/ 问答频道 /正文

因为我现在正在使用windows注册表。。我总是发现以下模式。。注册表包含两个括号{},中间有数字和字母,您可以看到下面的一些示例:

HKEY_CLASSES_ROOT\Drive\shellex\FolderExtensions\{fbeb8a05-beee-4442-804e-409d6c4515e9}

HKEY_CLASSES_ROOT\CLSID\{00BB2763-6A77-11D0-A535-00C04FD7D062}\InProcServer32

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\CPC\Volume\{64dcb6fa-03c9-11e6-9e9f-806d6172696f}\

有谁能帮助我理解这些是指什么?它们是随机生成的吗?在

我还试图解析每个注册表项并删除方括号{}之间的任何内容。。首先,我知道这可以用正则表达式实现,但我真的不熟悉它们。。欢迎任何指导。在


Tags: 示例注册表windows字母模式数字rootdrive
3条回答

当您用Python标记问题时(用2.7测试):

import re

string = """
HKEY_CLASSES_ROOT\Drive\shellex\FolderExtensions\{fbeb8a05-beee-4442-804e-409d6c4515e9}
HKEY_CLASSES_ROOT\CLSID\{00BB2763-6A77-11D0-A535-00C04FD7D062}\InProcServer32
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\CPC\Volume\{64dcb6fa-03c9-11e6-9e9f-806d6172696f}
"""

rx = r'\{[^}]+\}\\?'
string = re.sub(rx, '', string)
print string

代码片段提供了所有不带大括号的键。感谢@Liam之前指出了一个错误。
提示:我是一个Mac用户,但是,我很确定大括号是有必要的,不是吗?在

{.*?}替换为{}(如果一行有两个guid,则使用lazy dot)

demo

字符串是Globally Unique Identifiers。从here

GUID (or UUID) is an acronym for 'Globally Unique Identifier' (or 'Universally Unique Identifier'). It is a 128-bit integer number used to identify resources. The term GUID is generally used by developers working with Microsoft technologies, while UUID is used everywhere else.

128-bits is big enough and the generation algorithm is unique enough that if 1,000,000,000 GUIDs per second were generated for 1 year the probability of a duplicate would be only 50%. Or if every human on Earth generated 600,000,000 GUIDs there would only be a 50% probability of a duplicate.

GUIDs are used in enterprise software development in C#, Java, and C++ as database keys, component identifiers, or just about anywhere else a truly unique identifier is required. GUIDs are also used to identify all interfaces and objects in COM programming.

在这种情况下,正则表达式是最好的。只需使用:

import re
string = 'HKEY_CLASSES_ROOT\CLSID\{00BB2763-6A77-11D0-A535-00C04FD7D062}\InProcServer32'
string = re.sub('{(.+)}', '', string)

相关问题 更多 >

    热门问题