I am trying to generate a PHP function name from URL using this regular expression (taken from PHP Manual – User-defined functions:
url = "controller/action,/param";
re = /[^a-zA-Z0-9_\x7f-\xff]*/g; // consecutive characters that are not in range
result = url.replace(re, "_");
I am expecting result to be controller_action_param (single underscore), but instead I am getting this as a result: _c_o_n_t_r_o_l_l_e_r__a_c_t_i_o_n__p_a_r_a_m_
I think that this is somehow connected to UTF-8/Unicode, but shouldn’t \x7f-\xff part take care of it?
Change the
*to a+. The*matches zero or more of the preceding characters, you want one or more.