PHP - Split street name and street address

I need to strip street numbers from street name. I face the problem when there is no numerical part like Avenue ABC or when street name starts with number like 10. Street 46.

My regex right now is:

([^\d]+)\s?(.+)

These are test strings:

St. Stephen 12
Avenue ABC
Avenue AB
10. Street 46

Result should looks like:

array = (0 => 'St. Stephen', 1 => '12')
array = (0 => 'Avenue', 1 => 'ABC')
array = (0 => 'Avenue', 1 => 'AB')
array = (0 => '10. Street', 1 => '46')

Live regex: http://www.phpliveregex.com/p/cil

Answers


You may use the below regex which produces two captures of one contains all the chars upot the last space where another group contain last word.

^(.+)\s(.+)

DEMO


Need Your Help

Optimize linq query for performance(now takes 12-15seconds, need 3seconds)

sql performance tsql linq-to-entities query-optimization

Edit: I need help to rewrite these linq querys to SQL querys for highest possible performance.

How to move a item from one menu to another?

c# winforms visual-studio-2005

In the Visual Studio designer, how do you move a menu item from one menu to another? I would assume DnD would work, but it seems to only work within a menu for me.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.