A regular expression that only matches nothing?

S

steve.chambers

Can such a thing be done?

To explain myself a bit better I need a regular expression that will
only match an empty string ("") - if there is any text in the string I
don't want it to match. Won't go into why, it would take too much
explanation!

Thanks for any help/suggestions...

Cheers,
Steve
 
E

Eric Sosman

Can such a thing be done?

To explain myself a bit better I need a regular expression that will
only match an empty string ("") - if there is any text in the string I
don't want it to match. Won't go into why, it would take too much
explanation!

Pattern empty = Pattern.compile("^$");
 
J

Jeffrey Schwab

I need a regular expression that will
only match an empty string ("") - if there is any text in the string I
don't want it to match. Won't go into why, it would take too much
explanation!

..{0}
 
S

steve.chambers

Both seem to work, not sure which is best but will probably go with the
..{0} suggestion as its meaning seems slightly more intuitive.

Thanks v. much to both of you for the helpful suggestions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top