Regular Expressions in C#
-
Does anyone of you can answer to my question? I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET Regular Expressions show me which character (which character index in this incorrect string) is invalid. Please help me... -- modified at 15:53 Thursday 16th March, 2006 Is it possible with .NET regular expressions?
-
Does anyone of you can answer to my question? I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET Regular Expressions show me which character (which character index in this incorrect string) is invalid. Please help me... -- modified at 15:53 Thursday 16th March, 2006 Is it possible with .NET regular expressions?
No. Sorry. You can only perform positive matching with .NET REs.
-
No. Sorry. You can only perform positive matching with .NET REs.
-
Does anyone of you can answer to my question? I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET Regular Expressions show me which character (which character index in this incorrect string) is invalid. Please help me... -- modified at 15:53 Thursday 16th March, 2006 Is it possible with .NET regular expressions?
conrado7 wrote:
Is it possible with .NET regular expressions?
Yes, but a bit long winded. "(?(?[0-9])(?**[0-9])-(?[0-9])(?[0-9])(?[0-9]))" 1. Run with explicit capture. 2. Validate "valid" group. 3. If fail, validate each subgroup. Depending on the actual RE it mite be easier to just handwrite a 'parser'. :)
**
-
conrado7 wrote:
Is it possible with .NET regular expressions?
Yes, but a bit long winded. "(?(?[0-9])(?**[0-9])-(?[0-9])(?[0-9])(?[0-9]))" 1. Run with explicit capture. 2. Validate "valid" group. 3. If fail, validate each subgroup. Depending on the actual RE it mite be easier to just handwrite a 'parser'. :)
**
-
You sugested that in a more difficult regular expression the better thing to do is to write my own regular expression parser? Do you have any idea how I suppose to do this?
conrado7 wrote:
You sugested that in a more difficult regular expression
I meant an easier RE as per your example. It will probably just be easier to read the string char by char :)
-
conrado7 wrote:
You sugested that in a more difficult regular expression
I meant an easier RE as per your example. It will probably just be easier to read the string char by char :)
-
I`ve been wondering about creating my own parser, but in more difficult RE it`s very hard to build it. For e.g. ^(/d{2}-/d{3}){3,}$ Reg Exp... How can my parser read this to show me wich character is invalid? Any ideas?
The only way is to use sub group matching as per my example earlier.