We have the next SQL query in Postgresql 9.3
SELECT
regexp_split_to_array('merchant - mall', '(?!^)\s*(?!\d)[\-]\s*(?!\d)\s*(?=.)') as text1,
regexp_split_to_array('merchant - street 245', '(?!^)\s*(?!\d)[\-]\s*(?!\d)\s*(?=.)') as text2,
regexp_split_to_array('merchant - street-245', '(?!^)\s*(?!\d)[\-]\s*(?!\d)\s*(?=.)') as text3,
regexp_split_to_array('merchant - street - 245', '(?!^)\s*(?!\d)[\-]\s*(?!\d)\s*(?=.)') as text4
The result is:
"{merchant,mall}","{merchant,street 245}","{merchant,street-245}","{merchant,street,245}"
The problem is that 4th sample considers the number as a separate string. Is there any way of doing this with regex in postgresql?
The regex used (in the query) is:
(?!^)\s*(?!\d)[\-]\s*(?!\d)\s*(?=.)