Re: Regular Expression to enforce format?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.



.



Relevant Pages

  • Re: RegExp irregularity in JScript
    ... we believe the VBScript Regular Expression class (version 1.0 through ... It does not however, limit the string minimum 4, maximum 8 characters. ... Obviously the first test should test the length of the string, minimum 4, ...
    (microsoft.public.scripting.jscript)
  • Re: Usename regex
    ... Think of a string, ... Regular expression benchmark ... MS MAX AVG MIN DEV INPUT ... If the textbox in question is limited to say 16 characters you'd ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Fast search for all positions in a string
    ... It addition to running timing tests in different browsers and on ... direct string comparison (which is unintuitive given the relative ... The otherwise often problematic characteristic of Regular expression ... turns all characters that are significant in regular expressions ...
    (comp.lang.javascript)
  • Re: Regular Expression taking excessive CPU
    ... > regular expression adding so much time to the process, ... > ftIndex is a string variable that typically won't exceed 100 characters. ... static string RemoveNonAlpha1 ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Extracting Strings
    ... regular expression and php function that does it. ... I want to extract the data in the following string: ... The characters in the square brackets are the characters to match ...
    (alt.php)