[ticket/10423] Move code into a function and add tests for it

PHPBB3-10423
[ticket/10423] Match multiple wildcards

Multiple wildcards are removed from the string if there is
no word before or after them. If there is a word before or
after them, they are just replaced with a single one.

PHPBB3-10423