只有正则表达式:数字、字母和重音符号
Regex with only: numbers, letters and accents
我需要使用 PHP.
将字符串过滤为 return 只有 "numbers, letters and letters with accents"
我试过很多不同的正则表达式,但我做不到。
我得到的最接近的是:
$string = 'Você está bem? 123 # ! @ ...';
echo preg_replace('/[^\w\s+$]/', '_', $string);
// Return: Voc__ est__ bem_ 123 _ _ _ ___
// But I need to return: Você_está_bem_123 _ _ _ ___
有人可以帮助我吗?我花了几个小时试图解决它,甚至在这里寻找其他问题。
添加一个/u
修饰符:
$string = 'Você está bem? 123 # ! @ ...';
echo preg_replace('/[^\w\s+$]/u', '_', $string);
^
SO 正则表达式文档中有关 /u
修饰符的更多信息:
Pattern and subject strings are treated as UTF-8.
我需要使用 PHP.
将字符串过滤为 return 只有 "numbers, letters and letters with accents"我试过很多不同的正则表达式,但我做不到。
我得到的最接近的是:
$string = 'Você está bem? 123 # ! @ ...';
echo preg_replace('/[^\w\s+$]/', '_', $string);
// Return: Voc__ est__ bem_ 123 _ _ _ ___
// But I need to return: Você_está_bem_123 _ _ _ ___
有人可以帮助我吗?我花了几个小时试图解决它,甚至在这里寻找其他问题。
添加一个/u
修饰符:
$string = 'Você está bem? 123 # ! @ ...';
echo preg_replace('/[^\w\s+$]/u', '_', $string);
^
SO 正则表达式文档中有关 /u
修饰符的更多信息:
Pattern and subject strings are treated as UTF-8.