skip to Main Content

JavaScript regex to standardize US zipcode

I can't figure out whats what with a regex. The simplest reproduction is this failed match where I would expect that 3rd capture group to be 'A'.: > console.log('00000-0000A'.match(/(D)s*(d{5}-d{4})s*(D)/g)); null undefined Additional context includes: const standardizeZipcode = (str: string) =>…

VIEW QUESTION

Javascript Regex Lookahead

I am not understanding why this regex pattern is not matching as expected. I am testing this pattern on https://regexr.com. regex =/^1?((?=d{3}))[-. ]?(d{3})$/ sample = 1(123) 123 My understanding is first pattern should be number 1 or nothing then 3…

VIEW QUESTION
Back To Top
Search