How to find and remove string in front of URL? We have a url pattern of [node:menu-link:parents:join-path]/[node:title].

We are finding that it is resulting in the following urls and we wanted to see if we could use hook_pathauto_alias_alter to remove the undesired string. We are finding that when doing the preg_replace, that is removing all instances where the "/" is found. We just want to remove the string upto the first "/" character. Need assistance in figuring out why it is not working. 

function mymodule_pathauto_alias_alter(&amp;$alias, array &amp;$context) {
       $patt = '.+(\/)';
       $replacement = '';
       preg_replace($patt, $replace);
}


Current results:


some-text/menu-linka/menu-linkb
some-text/menu-linka/menu-linkb/menu-linkc


Desired results:


menu-linka/menu-linkb
menu-linka/menu-linkb/menu-linkc
I see many problems in the code you posted in your question. First of all, you are missing a parameter in preg_replace. Take a look at the PHP documentation.

Second, you have no delimiters in your pattern. The correct pattern should be:

$patt = '/.+\//';

(You don't need the parenthesis, but you do need delimiters such as slash bars. See this).

Third, preg_replace() returns an array with the replacement. You need to assign the result to $alias, as in $alias = preg_replace(...)

I have not use this hook before, but keep in mind (from the description) that this is only invoked before the alias is saved.