I need to find the matching GUID in string using Regex
string findGuid="hi sdkfj 1481de3f-281e-9902-f98b-31e9e422431f sdfsf 1481de3f-281e-9902-f98b-31e9e422431f"
var guid = Regex.Match(m.HtmlBody.TextData, @"^(\{){0,1}[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}(\}){0,1}$").Value;
You may use Guid.TryParse on splitted array. Something like:
string findGuid = "hi sdkfj 1481de3f-281e-9902-f98b-31e9e422431f sdfsf 1481de3f-281e-9902-f98b-31e9e422431f";
string[] splitArray = findGuid.Split();
List<Guid> listofGuid = new List<Guid>();
foreach (string str in splitArray)
{
Guid temp;
if (Guid.TryParse(str, out temp))
listofGuid.Add(temp);
}
This will give you two items in the list of Guid
EDIT: For the new string as per comment of the OP,
string findGuid="hi sdkfj x-Guid:1481de3f-281e-9902-f98b-31e9e422431f sdfsf x-Guid:1481de3f-281e-9902-f98b-31e9e422431f"
Multiple split delimiters may be specified something like:
string[] splitArray = findGuid.Split(' ', ':');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With