Guid Regex help on validate pattern

ZM 211 Reputation points
2022-04-07T11:05:24.99+00:00

hi i would like some help to validate a pattern before releases the regex is correct but not entirely what im looking for

this is the regex I want however, im looking for it be exact, meaning it has start always with 8 and end with 12. as \w means any digit

Regex: \w{8}-\w{4}-\w{4}-\w{4}-\w{12}

so I can validate the pattern below with it exactly:
ddd30904-6845-4ca6-84d6-9c9a75756e76
66211f6b-e2f5-926a-4f45-b7aaff8262a9
7f14135e-c257-44cd-b76c-28e7c4aa90d0
400382fa-f551-41a6-b2e2-ab4d719fdf57

what would the new regex be?

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Givary-MSFT 35,621 Reputation points Microsoft Employee Moderator
    2022-04-07T13:27:00.79+00:00

    @SakeriyeMohamud-4520 Thank you for reaching out to us.

    I have tested your above regex \w{8}-\w{4}-\w{4}-\w{4}-\w{12} with the one of guid provided in the question, however it works but if i add any extra character to the guid, it doesnt give desired results as expected.

    Then researched and found the following regex ^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$ and tested with the one of the guid in the question, it works as expected. i have tested by adding extra character to one of the set in the guid to verify the results, below is the screenshot for your reference.

    190910-image.png

    If you want to use the same regex \w{8}-\w{4}-\w{4}-\w{4}-\w{12} with the guid mentioned in the question, i need to check how this regex ( give me day's time ) if it can be tweaked to meet the desired results correctly.

    Let me know if you have any questions.

    Please remember to "Accept Answer" if answer/reply helped, so that others in the community facing similar issues can easily find the solution.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.