【发布时间】:2011-12-06 18:04:51
【问题描述】:
我正在尝试将此 php 函数转换为 javascript:
function sanitize_words($string,$limit=false) {
preg_match_all("/\p{L}[\p{L}\p{Mn}\p{Pd}'\x{2019}]{1,}/u",$string,$matches,PREG_PATTERN_ORDER);
return $matches[0];
}
基本上,它需要这个字符串:
$string = "Why hello, how are you?"
$array = sanitize_words($string);
并将其转换为数组:
$array[0] = 'Why';
$array[1] = 'hello';
$array[2] = 'how';
$array[3] = 'are';
$array[4] = 'you';
它在 php 上运行良好,但我不知道如何在 javascript 上实现它,因为phpjs.org 中没有 preg_match_all。有任何想法吗?谢谢。
【问题讨论】:
标签: php javascript regex preg-match-all