469,898 Members | 1,417 Online

# 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
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.