2012-04-05 75 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

相關問題