Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Flex中的正则表达式_Regex_Actionscript 3_Apache Flex_Flex4.5 - Fatal编程技术网

Regex Flex中的正则表达式

Regex Flex中的正则表达式,regex,actionscript-3,apache-flex,flex4.5,Regex,Actionscript 3,Apache Flex,Flex4.5,我想检查字符串是否为空(只有空格也算为空)。如何在actionscript中组合正则表达式?模式应该类似于/^\s*$/(对于单行字符串)^和$表示行的开始和结束,\s*表示匹配零个或多个空白字符。例如: var s:String = /* ... */; var allWhitespaceOrEmpty:RegExp = /^\s*$/; if (allWhitespaceOrEmpty.test(s)) { // is empty or all whitespace } else {

我想检查字符串是否为空(只有空格也算为空)。如何在actionscript中组合正则表达式?

模式应该类似于
/^\s*$/
(对于单行字符串)
^
$
表示行的开始和结束,
\s*
表示匹配零个或多个空白字符。例如:

var s:String = /* ... */;
var allWhitespaceOrEmpty:RegExp = /^\s*$/;
if (allWhitespaceOrEmpty.test(s))
{
    // is empty or all whitespace
}
else
{
    // is non-empty with at least 1 non-whitespace char
}
也许正如评论员亚历山大·法伯(Alexander Farber)所指出的,一种更简单的方法是检查除空白字符以外的任何字符,空白字符在正则表达式中由
\S
匹配:

var nonWhitespaceChar:RegExp = /\S/;
if (nonWhitespaceChar.test(s))
{
    // is non-empty with at least 1 non-whitespace char
}

对于多行字符串,有什么区别吗?添加
(?s)
多行开关:
/(?s)^\s*$/
,这样它将同时适用于单行字符串和多行字符串,对吗?单行字符串是多行字符串,其中行数
1
,因此对/\s+/的检查更加简单