开发者

RegExp alphanumeric String + Special Letters

First question : I want to replace all characters other than alphanumeric and Special Letters. Fo开发者_JAVA技巧r example , somestringğüş iöç123456!@#$%^&*()_+ to somestringğüş iöç123456

Second: For example , some---example--long-string to some-example-long-string

I do not really know regexp , so I need 2 simple regexp strings.Thank you


First. It matches any character that is not alphanumeric, whitespace or non-ascii, and replaced them with the empty string.

str.replace(/[^a-z0-9\s\x80-\uFFFF]+/gi, '');

There are no unicode-classes that I can use, so either I include all unicode characters, or list the ones that are not letters, digits nor whitespace.

Second. It matches any sequence of two or more dashes, and replaces them with a single dash.

str.replace(/-{2,}/g, '-');


 /* 1. */   return x.replace(/[!@#$%^&*()_+]/g, '');
 /* 2. */   return x.replace(/-{2,}/g, '-');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜