I am having problems trying to write a PHP Regex matching pattern to match and split string into needed groups.
Here is the situation... I have a multiple strings with contacts:
+35 00000000, info@company.com, www.company.com
This would give me:
Group 1: +35 00000000, info@company.com, www.company.com
+35 00000000, +360000000, info@company.com, www.company.com
This would give me:
Group 1: +35 00000000
Group 2: +36 00000000, info@company.com, www.company.com
info@company.com, www.company.com
This would give me:
Group 1: info@company.com, www.company.com
+35 00000000, info@company1.com, www.company1.com, +36 00000000, info@company2.com, www.company2.com
This would give me:
Group 1: +35 00000000, info@company1.com, www.company1.com
Group 2: +36 00000000, info@company2.com, www.company2.com
As you can see, these strings can be different. What I need to do is split those strings into groups of contacts, which:
- often start with phone number (+), but not always and can contain only one
- can start with website link or with email if no phone is provided
- can contain multiple groups of different companies
So at first I tried to match groups starting with phone number and ending with website:
((\+?[\d ]+)?(, )?(.*)(, )?(www\.\w+\.\w{2,})?)
But this does not match exact. Also then tried to simplify everything ant match groups that start with phone numbers:
(\+[\d ]+).*
But this matches full strings.
Have to say I'm a big noob regarding Regex. I manage to do basic matchings, but this is too hard for me.
Length of pattern or low performance is not important as this will be a one-time execution.