Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Understanding a RegEx expression
Message
 
To
11/03/2014 14:18:41
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01596120
Message ID:
01596134
Views:
75
This message has been marked as the solution to the initial question of the thread.
>When I first looked at the first one, I thought this meant alphanumeric characters + a dash character in all characters from 1 to 20 MINUS alphanumeric only in the first 12 characters. Which means, the dash would have been accepted only from position 13th and up.
>
>But, support gave me information that this means the dash is supported from position 2 and up.
>
>I really do not know what to believe now.

([A-Za-z0-9-]{1,20}) : at least one but less than 21 characters chosen from A to Z, a to z, 0 to 9 or the dash
- : the previous group MUST be followed by a dash (so yes, it means it is supported from position 2 and up to 21, not supported in position 22)
([A-Za-z0-9]{1,4}) : at least one but less than 5 characters chosen from A to Z, a to z, 0 to 9

So all of the following are valid:
-A-B
--B
ABC-DEF
ABC--DEF
AA--AB

Which I am not sure is what you want, I think you do not want the dash in the first expression?

NOTE: Position above refers to the relative position from the start of the matched string, if you want it to match only at START or/and END you must include ^ or/and $ for example

12345678901234567890--DEF will match even thou it has 22 characters before the mandatory dash, but your regex will match from the 2 on (2345678901234567890--DEF), to avoid this you need to start the regex with ^
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform