Code: Select all
preg_split('#(\W+)\([A-Z]{2}\)#', $subject);Code: Select all
Winnipeg (MB)
Regina (SK)
Toronto (ON)Obviously the regex I have written does not work, it only matches the city and ignores the province...
Moderator: General Moderators
Code: Select all
preg_split('#(\W+)\([A-Z]{2}\)#', $subject);Code: Select all
Winnipeg (MB)
Regina (SK)
Toronto (ON)Possibly, unless he wants to get the two parts (city & province) back separated, then split is appropriate here.pickle wrote:Why are you using preg_split()? preg_match() would seem to be a better fit.
...
Code: Select all
print_r(preg_split('/\s(?=\()/', 'Trois Rivieres (AB)'));
/*
Array
(
[0] => Trois Rivieres
[1] => (AB)
)
*/Code: Select all
$search_region = preg_split('#/\s(?=\()/#', $request->search_region, null, PREG_SPLIT_DELIM_CAPTURE);Code: Select all
Array
(
[0] => Winnipeg (MB)
)Code: Select all
print_r(preg_split('/\s(?=\()/', 'Winnipeg (MB)'));
/*
Array
(
[0] => Winnipeg
[1] => (MB)
)
*/But you see the difference, right? You're using double delimiters (both '/' and '#') while only one is needed.PCSpectra wrote:I copied your code verbatim and that seems to have fixed the issue, ...
You're welcome.PCSpectra wrote:... thanks a bunch