-2

I want to write a regular expression to match the given pattern

anyname/anyname2/anydate/string

anyname: It must accept valid names including underscore (_)

anyname2: It must accept valid names including underscore(_) or hiffen (-)

anydate: The date must be in the format like 'yyyy-mm-dd'. Ex: 2016-12-10

string: This string contains predefined strings. it needs to match only the required characters like, [computer],[desktop],[laptop]. Other than these 3, it should not match any other.

Note: The expression must also match '/' as in the above mentioned pattern

Community
  • 1
  • 1
Arjun Kesava
  • 740
  • 1
  • 10
  • 14

1 Answers1

0

Your requirements aren't terribly clear, but if I understand them correctly, then something like the following should work:

\w+/[\w\-]+/\d{4}-[01]\d-[0-3]\d/(computer|desktop|laptop)
Steven Doggart
  • 43,358
  • 8
  • 68
  • 105