regex - regexp for finding substring(vehicle number plate) in matlab from long string? -
i have long string "sdnak hsd fds fnsdf apsdf09sdf bn fddsdalf 7886sd f" string have extract "ap09bn7886" vehicle's licence plate number in india. know possibly easiest use regular expression, can tell me reg. exp find this.
as understand the format, indian license plates are:
- two uppercase latin letters representing indian state -
[a-z]{2}
- two digits representing sequential number within state,
\d{2}
- then 4 digits prefixed letters when run out of digits;
[a-z]*\d{4}
(number 1 , number 2 combined rto state , district)
you trying gather components of long string, , have not stated enough detail of other parts of string eliminate ambiguity (for example: letters lower case or non latin characters? 1 license plate per string? 2 letters prefixing 4 digits? etc) since not known, can represent 'sea' of characters between match groups .*?
the variable letters prior 4 digit number particularly ambiguous, since there unrelated uppercase latin letters in string.
you can use following regex find examples not find every commbo in strings out there:
([a-z]{2}).*?(\d{2}).*?([a-z]{2}).*?(\d{4})
then combine 4 capture groups.
if want more specific, use alteration first 2 letters according 2 letter codes states of india.
eg:
(as|nl|mh etc).*?(\d{2}).*?([a-z]{2}).*?(\d{4})
or, use more comprehensive match rto
if can further refine 'other' between capture groups, can use negative character class or an anchor .* more accurate:
# pseudo regex... # xxx (match or skip or anchor in between stuff...) (as|nl|mh etc)xxx(\d{2})xxx([a-z]*)xxx(\d{4})
then need think amout exceptions (special delhi region codes, diplomatic plates, vanity plates, military plates, o boy...)
Comments
Post a Comment