473,467 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Regular Expressions and Empty Strings

I'm experimenting with Regular Expressions and Windows Forms.
Frequently I want a value to be either a valid pattern or empty. For
example a Zip code must be 5 digits or may be empty. I know that I can use
the Regular Expression "\d{5}" to test for exactly 5 digits. How can I add
the option for the string to be empty or must I always test the value before
calling the Regular Expression?

Thanks
Nov 20 '05 #1
2 2458
Cleo,
Have you tried alternation?

Something like:
Const pattern As String = "^\d{5}$|^$"

The following sites provide a wealth of information on regular expressions.

A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay

"cleo" <cl**@missinformation.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I'm experimenting with Regular Expressions and Windows Forms.
Frequently I want a value to be either a valid pattern or empty. For
example a Zip code must be 5 digits or may be empty. I know that I can use the Regular Expression "\d{5}" to test for exactly 5 digits. How can I add the option for the string to be empty or must I always test the value before calling the Regular Expression?

Thanks

Nov 20 '05 #2
Thanks, this expression works. I wasn't aware of the $ expression. The
tutorial references are helpful since I haven't found much just browsing VB
Help.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:u7**************@TK2MSFTNGP11.phx.gbl...
Cleo,
Have you tried alternation?

Something like:
Const pattern As String = "^\d{5}$|^$"

The following sites provide a wealth of information on regular expressions.
A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp
Hope this helps
Jay

"cleo" <cl**@missinformation.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I'm experimenting with Regular Expressions and Windows Forms.
Frequently I want a value to be either a valid pattern or empty. For
example a Zip code must be 5 digits or may be empty. I know that I can

use
the Regular Expression "\d{5}" to test for exactly 5 digits. How can I

add
the option for the string to be empty or must I always test the value

before
calling the Regular Expression?

Thanks


Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Des Small | last post by:
I want to use sets and regular expressions to implement some linguistic ideas. Representing sounds by symbols, and properties (coronal or velar articulation; voicedness) by sets of symbols with...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
5
by: ST Wong | last post by:
Hi all, As metacharaters ^ and $ are not used in regular expression in XML, I'm looking for how to specify empty string. Would anyone please help? Thanks a lot. Regards, ST Wong
22
by: stoppal | last post by:
need to extract all text between the following strings, but not include the strings. "<!-- #BeginEditable "Title name" -->" "<p align="center">#### </p>" I am using preg_match(????, $s,...
9
by: Schorschi | last post by:
Not having used regular expressions much, I need some help. Given a string... "This\0Guy\0Needs\0Some\0Help\0\0\0\0\0" Need result as array of strings... "This","Guy", "Needs", "Some", "Help" ...
5
by: Trevor Braun | last post by:
Hi, I'm not sure that this is the right forum for this, but I've been having a very tough time completing this expression, and I was hoping someone might have some suggestions for me. I am trying...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
7
by: PJ6 | last post by:
Is it possible for a regular expression to macth only an empty string? What I want is exactly {0}, but that causes the parser to throw an exception - parsing "{0}" - Quantifier {x,y} following...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.