0
static final Pattern EXAMPLE_PATTERN = ~/[A-Z0-9\[][A-Z0-9&\/][A-Z0-9]{1,4}/

This is a regex I was given and I am struggling to understand what exactly it limits. Thanks!

tim_yates
  • 154,107
  • 23
  • 313
  • 320
ladyskynet
  • 187
  • 1
  • 1
  • 10

2 Answers2

0
  • [A-Z0-9\[] means a character that is an uppercase letter, a number, or [
  • [A-Z0-9&\/] means a character that is an uppercase letter, a number, & or /
  • [A-Z0-9]{1,4} means one to four characters that is are an uppercase letter, or a number

So AA0000 will match. As will A[9 and F/1234

But aaa wont. Nor will AA

tim_yates
  • 154,107
  • 23
  • 313
  • 320
0
 [A-Z0-9\[]           # Single character,  of class A-Z or 0-9 or [
 [A-Z0-9&/]           # Single character,  of class A-Z or 0-9 or & or /
 [A-Z0-9]{1,4}        # 1 to 4 characters, of class A-Z or 0-9