Reputation: 1509
I want to check if the string is not empty (having whitespaces only also counts as empty). How to compose the regular expression in actionscript?
Upvotes: 0
Views: 312
Reputation: 24177
The pattern should be something like /^\s*$/
(for a single line string); ^
and $
represent the start and end of the line and \s*
means match zero or more whitespace characters. For example:
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
}
Perhaps a simpler way as commenter Alexander Farber points out is to check for any character except a whitespace character, which is matched by \S
in regex:
var nonWhitespaceChar:RegExp = /\S/;
if (nonWhitespaceChar.test(s))
{
// is non-empty with at least 1 non-whitespace char
}
Upvotes: 1