DTwined
asked on
regular expression match empty string
Hello -
I need a regular expression that will tell me if the string I am looking at is empty.
Thanks,
DT
I need a regular expression that will tell me if the string I am looking at is empty.
Thanks,
DT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The string is one line.
@DTwined: Because you are using a single line string the above code will work. Depending on your programming language though, there are probably better ways to do this with trimming and checking for zero length. Some languages provide helper methods like string.IsNullOrEmpty and string.IsNullOrWhiteSpace in .NET.
@kaufmed: If the string was multi-line then it actually contains characters (carriage returns and/or line feeds). The above regular expression means it genuinely empty.
@kaufmed: If the string was multi-line then it actually contains characters (carriage returns and/or line feeds). The above regular expression means it genuinely empty.
If the string was multi-line then it actually contains charactersI didn't say the string would be multi-line; I said the multi-line modifier is turned on, which changes the meaning of ^ and $. However, when I tested it didn't seem to make a difference, so my comment above may be moot anyway = )
... provided you don't turn on the multi-line modifier.