regular expression match empty string

Hello -

I need a regular expression that will tell me if the string I am looking at is empty.

Who is Participating?
brutaldevConnect With a Mentor Commented:
The following expression expects nothing to be matched (an empty string).

Open in new window

käµfm³d 👽Commented:

... provided you don't turn on the multi-line modifier.
DTwinedAuthor Commented:
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.
käµfm³d 👽Commented:
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  = )
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.