[Answer]-Writing '-' in regular expression django url

1👍

Check one upper case letter, then dash, then exactly 3 digits, the dash and a single upper case letter:

url(r'^StorageLocation/[A-Z]\-[0-9]{3}\-[A-Z]$', views.StorageLocation, name='StorageLocation'),

Demo:

>>> import re
>>> pattern = re.compile(r'[A-Z]\-[0-9]{3}\-[A-Z]')
>>> pattern.match('E-152-A')
<_sre.SRE_Match object at 0x103aba6b0>
>>> pattern.match('E-112-B')
<_sre.SRE_Match object at 0x103abab90>
👤alecxe

Leave a comment