Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript正则表达式仅限字母和数字以及破折号UTF8_Javascript_Php_Regex_Utf 8 - Fatal编程技术网

Javascript正则表达式仅限字母和数字以及破折号UTF8

Javascript正则表达式仅限字母和数字以及破折号UTF8,javascript,php,regex,utf-8,Javascript,Php,Regex,Utf 8,有php正则表达式吗 $string = preg_replace("/[^\p{L}|\p{N}]+/u", " ", $string); $string = str_replace(' ', '-', $string); 帮我把它写在js上,需要转换吗 jbgsbg5%E-th-t65?tw45@%^&*j-y&u-САМОЛЁТ~ ~2><%27;[]~!6456 谢谢 您可以使用[^a-z0-9\-…ЛЁ…]删除所有非字母、非数字和非破折号: var

有php正则表达式吗

$string = preg_replace("/[^\p{L}|\p{N}]+/u", " ", $string);
$string = str_replace(' ', '-', $string);
帮我把它写在js上,需要转换吗

jbgsbg5%E-th-t65?tw45@%^&*j-y&u-САМОЛЁТ~   ~2><%27;[]~!6456

谢谢

您可以使用
[^a-z0-9\-…ЛЁ…]
删除所有非字母、非数字和非破折号:

var foo = 'jbgsbg5%E-th-t65?tw45@%^&*j-y&u-САМОЛЁТ~   ~2><%27;[]~!6456';

foo
    .replace(/\s+/g, "") // remove whitespaces
        .replace(/[^a-zA-Z0-9\- ... ЛЁ ... ]/ig, "") // remove non-letters, non-numbers and non-dash characters
            .replace(/\-+/g, '-'); // replace multiple `-` character with single `-`

var foo='jbgsbg5%E-th-t65?tw45%^&*j-y&u-САММЛЁ圪~~~2>您可以在javascript中尝试使用此正则表达式:

[\u00BF-\u1FFF\u2C00-\uD7FF\w\-]+

仅限字母、数字和破折号UTF8 JS

link = link.replace(/[^\u00BF-\u1FFF\u2C00-\uD7FF\w]+|[\_]+/ig, '-');

JavaScript中的正则表达式不支持unicode类,例如
\p{L}
;您必须亲自编写它们。您是否可以编写一个包含变量的完整javascript,这是可行的,但无法理解如何在JS上编写。无需更改
\\\\\+
,下划线已包含在
\w
中。
link = link.replace(/[^\u00BF-\u1FFF\u2C00-\uD7FF\w]+|[\_]+/ig, '-');