我有一个可以识别 Guid 的正则表达式。
string pattern = @"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
我有一个可以识别数字的正则表达式
string pattern = "^[0-9]+$"
我需要结合这两个正则表达式。
我的任务是从句子中识别以下类型的字符串。
Input : id=1 name=4a3779ab-56cc-41b5-ac7c-03bbf673439c-53607.jpg count=53607
Output : 4a3779ab-56cc-41b5-ac7c-03bbf673439c-53607.jpg
or just 4a3779ab-56cc-41b5-ac7c-03bbf673439c-53607
输出是一个 Guid,后跟一个破折号('-')和一个数字。
我怎样才能得到这种正则表达式?
您可以使用以下正则表达式:
\b[\dA-F]{8}-[\dA-F]{4}-[\dA-F]{4}-[\dA-F]{4}-[\dA-F]{12}-\d+
Demo https://regex101.com/r/kL7dU0/1
string input = "id=1 name=4a3779ab-56cc-41b5-ac7c-03bbf673439c-53607.jpg count=53607";
Match m = Regex.Match(input, @"\b[\dA-F]{8}-[\dA-F]{4}-[\dA-F]{4}-[\dA-F]{4}-[\dA-F]{12}-\d+", RegexOptions.IgnoreCase);
string output = null;
if (m.Success)
output = m.Value;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)