用于选择每个空白区域的正则表达式
如果语言/环境支持它,你可以使用\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]
我认为你的意思是'if($ str =〜m/\ s /)',你用'\ s'替代'$ str'中的模式替换语法('\ s'不能用作替换) – stema 2011-12-20 09:56:31
@stema哎呀,自从我完成perl以来已经有一段时间了。接得好。 – 2011-12-20 09:59:31
\ s是最佳匹配项为空白字符。这里的空白将被定义为[\ t \ n \ f \ r \ p {Z}]。
试试这个链接,C++正则表达式:http://userguide.icu-project.org/strings/regexp
你能告诉我们你已经尝试了组合?你使用什么编程语言? – BoltClock 2011-12-20 09:44:00
good ol''s' – 2011-12-20 09:44:31
我正在使用C++ lang – user336635 2011-12-20 09:49:56