469,898 Members | 1,417 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Very complicated Regular Expression Help

Is it possible to write a regular expression for this ?

Pattern: 999-99-999

Where 9 is any number from 0 to 9

However the user need not enter ALL the digits and dashes as given in
the format.

Whatever numbers and dashes he had entered must match the above format,
from left to right, for only the charcters he has entered.

For example
9
99
999
999-
999-9
999-99
999-99-
999-99-9
999-99-99
999-99-999

Any of the above should result in a match

Next, he can also put * before or after or before and after any of the
above combination

Ex

*9
*99
*999
*999-
*999-9
*999-99
*999-99-
*999-99-9
*999-99-99
*999-99-999

Or

9*
99*
999*
999-*
999-9*
999-99*
999-99-*
999-99-9*
999-99-99*
999-99-999*

Or

*9*
*99*
*999*
*999-*
*999-9*
*999-99*
*999-99-*
*999-99-9*
*999-99-99*
*999-99-999*

Any help is much appreciated.

Oct 6 '06 #1
5 2317
Jayanthigh,

Is this a school question, it does not look for me as a real life question.

Cor

<ja************@yahoo.comschreef in bericht
news:11**********************@m7g2000cwm.googlegro ups.com...
Is it possible to write a regular expression for this ?

Pattern: 999-99-999

Where 9 is any number from 0 to 9

However the user need not enter ALL the digits and dashes as given in
the format.

Whatever numbers and dashes he had entered must match the above format,
from left to right, for only the charcters he has entered.

For example
9
99
999
999-
999-9
999-99
999-99-
999-99-9
999-99-99
999-99-999

Any of the above should result in a match

Next, he can also put * before or after or before and after any of the
above combination

Ex

*9
*99
*999
*999-
*999-9
*999-99
*999-99-
*999-99-9
*999-99-99
*999-99-999

Or

9*
99*
999*
999-*
999-9*
999-99*
999-99-*
999-99-9*
999-99-99*
999-99-999*

Or

*9*
*99*
*999*
*999-*
*999-9*
*999-99*
*999-99-*
*999-99-9*
*999-99-99*
*999-99-999*

Any help is much appreciated.

Oct 6 '06 #2
Here is the expression you need:
\*{0,1}[0-9]{1,3}-{0,1}[0-9]{0,2}-{0,1}[0-9]{0,3}\*{0,1}

If you want to do search, replace and text exctracion with regular
expressions, try AJC Grep. See:
http://www.ajcsoft.com/AJCGrep.php
--
Andrew Cutforth - AJC Software - www.ajcsoft.com
The best folder synchronize and directory compare tool available.
AJC Active Backup instantly archives every file you edit giving you
unlimited undo and automatic revision control. Never lose your data again.
Oct 6 '06 #3

"Andrew" <so*****@nospam.comschrieb im Newsbeitrag
news:O%****************@TK2MSFTNGP04.phx.gbl...
Here is the expression you need:
\*{0,1}[0-9]{1,3}-{0,1}[0-9]{0,2}-{0,1}[0-9]{0,3}\*{0,1}
this would match f.e.:
99999999
or
--

wich is against the intension of the OP, i suppose.
>
If you want to do search, replace and text exctracion with regular
expressions, try AJC Grep. See:
http://www.ajcsoft.com/AJCGrep.php
--
Andrew Cutforth - AJC Software - www.ajcsoft.com
The best folder synchronize and directory compare tool available.
AJC Active Backup instantly archives every file you edit giving you
unlimited undo and automatic revision control. Never lose your data
again.


Oct 6 '06 #4
this would match f.e.:
99999999
or
--
Try this:
\*{0,1}[0-9]([0-9]([0-9](-([0-9]([0-9](-([0-9]([0-9]([0-9]|)|)|)|)|)|)|)|)|)\*{0,1}

Of course this will appear to match "9999" but that will be as two separate
correct matches of "999" and "9"

--
Andrew Cutforth - AJC Software - www.ajcsoft.com
The best folder synchronize and directory compare tool available.
AJC Active Backup instantly archives every file you edit giving you
unlimited undo and automatic revision control. Never lose your data again.
Oct 6 '06 #5
The proper regex for matching v4 IP addresses will give you your answer
if applied with a little creativity.

~Jason

--
Oct 6 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bradley Plett | last post: by
4 posts views Thread by Neri | last post: by
3 posts views Thread by James D. Marshall | last post: by
7 posts views Thread by Billa | last post: by
9 posts views Thread by Pete Davis | last post: by
3 posts views Thread by Zach | last post: by
25 posts views Thread by Mike | last post: by
reply views Thread by jayanthigk2004 | last post: by
3 posts views Thread by Mr.Steskal | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.