Re: Regular Expression to enforce format?
- From: "Kevin Spencer" <unclechutney@xxxxxxxxxxxx>
- Date: Fri, 29 Jun 2007 08:37:53 -0400
Here's your regular expression:
"1498159\102"
Since "1498159\102" is the format, "1498159\102" is the regular expression.
Any input that does not match that format will not pass.
Of course, now you're shaking your head, and thinking what a dumb jerk I am.
Well, let me plead my case:
"1498159\102" is not a format. It is a string. A regular expression
identifies patterns in strings. A pattern is defined by a set of rules
regarding sequences of characters, rather than a set of literal character
values. The rules of the pattern indicates what constitutes a matching
sequence of characters. The regular expression is a shorthand syntax for the
rules themselves. It may include literal characters and/or pattern tokens.
Like anything else in computing, the rules are specific and exact, and can
describe character types, character values, ranges of character values,
relationships of characters and character sequences to other characters and
character sequences, quantities of characters and sequences, conditional
logic, position of characters and sequences, etc.
So, while a regular expression can be used to derive whether a literal
string is a match for a pattern, a literal string can not be used to derive
a regular expression that contains rules that match the string.
For example, the following regular expressions will match your string:
..* (any number of any character)
\w+.\d{3} (1 or more alphanumeric characters, followed by any single
character, followed by 3 digits)
\d{6,}\\102 (6 or more digits, followed by a backslash, followed by the
sequence "102"
I hope you get my point. Can you explain the rules you want to use?
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
"C" <C@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:38F3FB59-5740-465A-91E1-5BDFBEA170E9@xxxxxxxxxxxxxxxx
Hi,
I have an asp.net textbox and I want to enforce that the user inputs
values
in the following format 1498159\102
How can I do this using a Regular Expression or otherwise?
Any advice appreciated.
.
- Follow-Ups:
- Re: Regular Expression to enforce format?
- From: Alexey Smirnov
- Re: Regular Expression to enforce format?
- Prev by Date: Re: Urgent Requirement For .NET Programmers In Bangalore
- Next by Date: Content-Type="Application/pdf" & Byte[]
- Previous by thread: Urgent Requirement For .NET Programmers In Bangalore
- Next by thread: Re: Regular Expression to enforce format?
- Index(es):
Relevant Pages
|