正则表达式:如何在长字符串中查找 GUID? [英] Regex: How to find a GUID in a long string?

查看:54
本文介绍了正则表达式:如何在长字符串中查找 GUID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个字符串:

str = 'something-rows-1973912739821738172-25892e17-80f6-415f-9c65-7395632f0223'

我需要删除 GUID 部分:

<块引用>

25892e17-80f6-415f-9c65-7395632f0223

这是我迄今为止所做的,但它不起作用:

c = re.compile('[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}\Z', 再.I)res = c.match(str)打印(资源)

有人可以帮忙吗?

解决方案

来自这个的回答,你需要这个:

[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}

工作示例:https://regex101.com/r/6pA9Rk/1>

Let's say I have this string:

str = 'something-rows-1973912739821738172-25892e17-80f6-415f-9c65-7395632f0223'

I need to remove GUID part:

25892e17-80f6-415f-9c65-7395632f0223

This is what I've so far but it isn't working:

c = re.compile('[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}\Z', re.I)
res = c.match(str)
print(res)

Can anyone please help?

解决方案

From this answer, you need this:

[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}

Working example: https://regex101.com/r/6pA9Rk/1

这篇关于正则表达式:如何在长字符串中查找 GUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆