我试图找到一种方法来从标题字符串的开头和结尾修剪空格.我正在使用它,但它似乎没有工作:
title = title.replace(/(^[\s]+|[\s]+$)/g, '');
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我试图弄清楚正则表达式将匹配任何不是字母或数字的字符.所以字符如(,, @,£,()等...
一旦找到,我想用空格替换它.
任何建议.
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?
如何在HTML中使用转义引号?我的代码是:
<body onload="setTimeout('window.location='http://somepage.com'', 1000)">
Run Code Online (Sandbox Code Playgroud)
正如您在当前示例中所看到的,有两个',和'正在使用.如何让它们逃脱它们以便上面工作?
onload内容是为我正在使用@ work工作的系统动态设置的.