Can you not just use:
SELECT SUBSTRING_INDEX(fullname, ',', 1) AS firstname
,SUBSTRING_INDEX(fullname, ',', -1) AS lastname
FROM table
I can't tell what you're trying to do with the match against ' '
but if you're just trying to trim whitespace you can use TRIM()
on those values.