将2个Javascript正则表达式语句合并为1

时间:2011-10-07 21:57:15

标签: javascript regex

有没有办法结合这些Javascript正则表达式线?

两者都很好。我只是想知道是否有更有效的方法。

type = type.replace(/\s+/g, '');  //removes space
type = type.replace('/', '');     // removes forward slash

谢谢。

3 个答案:

答案 0 :(得分:4)

type = type.replace(/[\s/]+/g, '');

答案 1 :(得分:1)

试试这个:

type = type.replace(/\/|\s+/g, '');

请注意/如何使用反斜杠进行转义。

答案 2 :(得分:0)

type = type.replace(/[/\s]/g, '');
相关问题