2011-12-20 85 views
3

選擇每個空白區域的正則表達式是什麼?我試圖做幾個組合,包括排除數字,數字等,但無濟於事。用於選擇每個空白區域的正則表達式

+2

你能告訴我們你已經嘗試了組合?你使用什麼編程語言? – BoltClock 2011-12-20 09:44:00

+4

good ol''s' – 2011-12-20 09:44:31

+0

我正在使用C++ lang – user336635 2011-12-20 09:49:56

回答

7

什麼簡單的

\s+ 
與MATCH_ALL方法或選項,這取決於你的語言

在一起嗎?

看到它here online on Regexr的好地方來測試正則表達式

+0

#stema謝謝,現在就試試。 +1 – user336635 2011-12-20 09:56:27

0

如果語言/環境支持它,你可以使用\s修改。

在Perl中:

$str = "my string that has spaces" 

if($str =~ m/\s/) 
{ 
    #it has a white space character 
} 

如果你不能直接使用\s,您可以在列表here結合所有項目到一個字符類。從該鏈接:

If ECMAScript-compliant behavior is specified, \s is equivalent to [\f\n\r\t\v]

+0

我認爲你的意思是'if($ str =〜m/\ s /)',你用'\ s'替代'$ str'中的模式替換語法('\ s'不能用作替換) – stema 2011-12-20 09:56:31

+0

@stema哎呀,自從我完成perl以來已經有一段時間了。接得好。 – 2011-12-20 09:59:31