Link to home
Start Free TrialLog in
Avatar of DTwined
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
ASKER CERTIFIED SOLUTION
Avatar of brutaldev
brutaldev
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kaufmed
__NO POINTS__

... provided you don't turn on the multi-line modifier.
Avatar of DTwined
DTwined

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.
If the string was multi-line then it actually contains characters
I 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  = )