[英]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.