Thread: C# regex help
View Single Post
Old 06-01-2009, 05:49 PM   #10 (permalink)
kmote
 

Join Date: Jul 2005

Location: England

Posts: 2,175

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: C# regex help

Quote:
Originally Posted by CrazeD View Post
Your code didn't work. Firstly I was required to use three numbers in each octet. I want it to accept only 1-3 numbers. I fixed that by changing {2} to {1,3}. Then I could only put two or three numbers in, one number didn't match because you put [0-9] twice. I made it so it was was like [0-9]{1,3}, but that gets me back to the same code I already messed with earlier and I don't get the results I want.



Your code also didn't work. The \d and \. didn't agree with it, so I made those [0-9] and . respectively. It worked, however, as long as three numbers are present I can add as many letters as I want.

For example, this matches: 1a1a1.2b2b2.3c3c3.4d4d4

I tried to fix it with this: [0-9]{1,3}[^A-Za-z](.[0-9]{1,3}){3}

But that doesn't help at all. Why?
What happened when you had \d and \.? I ask because . is a metacharacter that means basically anything and it needs to be escaped when outside a character class if you want it to be literal. The reason your negated class is not working is because it only checks character 2-4 depending on the previous repetition.
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is offline