2012-04-05 73 views

回答

2

尝试使用这个正则表达式搜索字符串:

// presume searchStr = '" hello"' or '"hello "' or '" hello world "' 
searchStr.replace(/(")\s+|\s+(")/g,'"'); //=> "hello" or "hello world" 

考虑到你所选择的答案,quaotation标记(")不包括在内?在这种情况下,trim就足够了。在非jquery脚本中:

searchStr.replace(/^\s+|\s+$/g,''); 
+0

啊,这看起来不错。我会试试看,谢谢! – mmmoustache 2012-04-05 11:33:04

相关问题