Edit again to trying to make it more clear.
Wich php regex pattern will give me a match array containing always 2 values wich is the 2 part of a string splitted by the "wordA" or "wordB". If the string do not containt those word, simply return the string as the first array an null in the second array.
Exemple:
preg_match("pattern","foo wordA bar",$match), $match will contain array['foo', 'bar']
preg_match("pattern","foo wordB bar",$match), $match will contain array['foo', 'bar']
preg_match("pattern","foo bar test",$match), $match will contain array['foo bar test', null]
I know that $match first value is always the string so I just don't write it.
OLD question:
I need to split a one line address into part. I can't find a way to capture street part but dont include the APP or APT word if present and if present, capture the words after it.
For exemple:
"5847A, rue Principal APP A" should match: (5847, A, rue Principal,A)
"5847A, rue Prince Arthur APT 22" should match: (5847, A, rue Prince Arthur, 22)
"1111, Sherwood street" should match: (1111, , Sherwood street, )
I'm using PHP.
What I have so far is: /^(\d+)(.*), (.*)(?:APP|APT)(?:\s*(.*))?$/i
wich wook with exemple 1 and 2. If I try to make the alternative (APP|APT) optionnal by adding an ? after it, then the third match include the word APP or APT...
Any idea how to exclude the optionnal and alternative APP or APT word from match?
Thank you
EDIT:
I can simplify the problem: How can I regex a string so the match return the same string minus the word APP or APT if he is present in the middle of it.