How do I use RegEx to extract something ending in zipcode -


if have text in format mail - {what want extract) 98012-2345 do? dont seem able regex termination

ddddd-dddd 

so far have tried pattern of mail (.*) [ddddd]-[dddd]

this using .net 4.6.

share|improve question
    
ok wierd have working "mail - (.*?) ([0-9][0-9][0-9][0-9][0-9])-([0-9][0-9][0-9][0-9])" guess need stop being newbie :-) – rahul chandran aug 29 '16 @ 0:44

the zip code regex want looks this:

\d{5}(?:-\d{4})? 

what have there can collapsed down [d]-[d], , further d-d, meaning match 2 literal d characters separated hyphen, not you're after.

in regex provided, i've made second part of zip code optional (as in many cases), meaning you'll match both partial (5-digit) , complete (9-digit) zip codes. sure validate zip code, isn't i'd recommend doing regex.

share|improve answer

your answer

 
discard

posting answer, agree privacy policy , terms of service.

not answer you're looking for? browse other questions tagged or ask own question.

Comments