繁体   English   中英

Flex中的正则表达式

[英]Regular expression in Flex

我想检查字符串是否不为空(只有空格也算作空)。 如何在动作脚本中编写正则表达式?

模式应该类似于/^\\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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM