阻止PHP将反斜杠添加到字符串[关闭]

I have a function that builds a regex based on an array. The problem is that PHP keeps adding backslashes to some of the characters, and it keeps messing up the regex.

Here is my function:

private static $allowedPermissions = [
/*SV*/   
    'user_add',
    'user_edit',
    'user_delete',
    'user_view'];


    $regexrule = '/';

    foreach (self::$allowedPermissions as $allowedPermission) {
        $regexrule .= '\b'.$allowedPermission.'\b';
        if(end(self::$allowedPermissions) !== $allowedPermission) $regexrule .='|';
    }

    $regexrule .= "/";
    return 'regex:'.$regexrule;

It is adding backslashes where I don't expect them:

regex:\/\\buser_add\\b|\\buser_edit\\b|\\buser_delete\\b|\\buser_view\\b|\\bpatient_add\\b|\\bpatient_edit\\b|\\bpatient_delete\\b|\\bpatient_view\\b|\\bmake_per\\b|\\bmake_per_withconfirmation\\b|\\bconfirm_per\\b|\\beval_per\\b|\\beval_per_withconfirmation\\b|\\bconfirm_per_report\\b\/

Backup screenshot of regex

Is there a workaround?

I found out that returning it in json format was adding the backslashes.