小编Jam*_*ery的帖子

从字符串的开头和结尾修剪空格

我试图找到一种方法来从标题字符串的开头和结尾修剪空格.我正在使用它,但它似乎没有工作:

title = title.replace(/(^[\s]+|[\s]+$)/g, '');
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

javascript regex

152
推荐指数
7
解决办法
20万
查看次数

正则表达式:任何不是字母或数字的字符

我试图弄清楚正则表达式将匹配任何不是字母或数字的字符.所以字符如(,, @,£,()等...

一旦找到,我想用空格替换它.

任何建议.

javascript regex

96
推荐指数
7
解决办法
17万
查看次数

Creating Slugs from Titles?

I have everything in place to create slugs from titles, but there is one issue. My RegEx replaces spaces with hyphens. But when a user types "Hi     there" (multiple spaces) the slug ends up as "Hi-----there". When really it should be "Hi-there".

Should I create the regular expression so that it only replaces a space when there is a character either side?

Or is there an easier way to do this?

javascript regex slug

6
推荐指数
3
解决办法
2102
查看次数

逃避问题

如何在HTML中使用转义引号?我的代码是:

<body onload="setTimeout('window.location='http://somepage.com'', 1000)">
Run Code Online (Sandbox Code Playgroud)

正如您在当前示例中所看到的,有两个',和'正在使用.如何让它们逃脱它们以便上面工作?

onload内容是为我正在使用@ work工作的系统动态设置的.

javascript

0
推荐指数
1
解决办法
67
查看次数

标签 统计

javascript ×4

regex ×3

slug ×1