I'm trying to extract address starting from house numbers if unit numbers are present in given string.
If unit numbers are not available, select whole string.
const adss1 = 'U 4 21 House Ave, Suburb State 2020';
const adss2 = 'U 14 21 House Ave, Suburb State 2020';
const adss3 = '21 House Ave, Suburb State 2020';
const regEx = /(([0-9]+)((\s+[a-zA-Z,]+|\s+[a-zA-Z,.]+\s){2,10})?(\#[0-9a-z-\-]+|\#\s+[0-9\-]+|[0-9\-]+))/g;
const match1 = adss1.match(regEx)
console.log(match1)
// [ '21 House Ave, Suburb State 2020' ]
const match2 = adss2.match(regEx)
console.log(match2)
//[ '14', '21 House Ave, Suburb State 2020' ]
const match3 = adss3.match(regEx)
console.log(match3)
//[ '21 House Ave, Suburb State 2020' ]
Current regex pattern works for adss1 and adss3 address type but not for adss2 variable.
Looking for recommendations to improve my regex pattern. Thanks