Regular Expressions 101

Community Patterns

Javascript GUID regex

0

Regular Expression
ECMAScript (JavaScript)

/
^(((?=.*}$){)|((?!.*}$)))((?!.*-.*)|(?=(.*[-].*){4}))[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}?[}]?$
/
gm

Description

Validate GUID using a regex expression.

Does not allow:

  • Mismatched enclosing braces.
  • Incorrect numbers of characters per grouping.
  • Incorrect number of groupings.
  • Invalid characters

Does allow:

  • Use of enclosing braces.
  • No enclosing braces.
  • Use of '-' to separate groupings.
  • Use of no '-' to separate groupings.
Submitted by stom - 4 years ago