Search code examples
regexaddressbookstreet-address

Regex to separate addresses information


I'd like to separate the data input by my user on their shipping information into the respective field. The data input will be in this format:

Name - Phone Number - Address

For Example:

Andy Leblanc    (0123-123-12312)   Seaview Av. Street no 21, East Singapore 11221

Name could be any characters, phone would be number with these characters possibly included: "()[]./- ", and address would again be any character.

So the 2 characters field are separated by a number field. Is this possible to separate using regex?


Solution

  • I came up with the following solution.

    My search regex is:

    ([\w\s]+)\s([\(\)\d-\[\]\.\/-]+)\s(.*)

    My replacement string is:

    Name:\1#Phone:\2#Address\3

    Edit: Included more characters in the phone section.