VB.NET regex searching for AAA-9999 -
i need finding first 3 capital letters a-z , space followed 4 numbers 0-9.
dim individualclasses matchcollection = regex.matches(allexitclasses(a), "([a-z])([a-z])([a-z]) ([0-9])([0-9])([0-9])([0-9])")
an example input string aml 4309
or def 4298
. above 7 characters want out of string.
edit: since preprocess input string, can use
dim individualclasses matchcollection = regex.matches(allexitclasses(a).replace(" ", "-"), "[a-z]{3}[-][0-9]{4}")
regex explanation:
[a-z]{3}
- 3 occurrences of english letters z[-]
- character class matching 1 hyphen[0-9]{4}
- 4 occurrences of digits 0 9.
note removed capturing groups since not seem using them @ all, , using limiting quantifiers, e.g. {4}
.
note use input string , previous regex [a-z]{3}\p{zs}[0-9]{4}
, need iterate through match collection , replace space in each match.value hyphen creating new array.
Comments
Post a Comment