Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Understanding a RegEx expression
Message
From
11/03/2014 15:27:41
 
 
To
11/03/2014 15:03:46
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:
01596142
Views:
38
>You are misinterpreting the {1,20} and {1,12}. These mean that the group preceding it is repeated between 1 and 20 or 1 and 12 times respectively. The expression you probably want is: ([A-Za-z0-9][A-Za-z0-9\-]{19})\-([A-Za-z0-9]{12})
>
>To break this expression down:
>The first [A-Za-z0-9] indicates the first character must be A-Z, a-z, or 0-9.
>The following [A-Za-z0-9\-]{19} indicates the next 19 characters must be A-Z, a-z, 0-9, or -.
>The parenthesis around these two make it into a capturing group.
>The next \- matches a literal hyphen.
>The final ([A-Za-z0-9]{12}) matches 12 characters of A-Z, a-z, or 0-9.
>
>If any of the blocks can be variable length, change the {n} to {n,m} where n is the least number of times that block can repeat, and m is the most it can repeat. http://www.regular-expressions.info/refrepeat.html also provides more information on the variations of the repeating indicator.

Thanks, this is very valuable.

Basically, this is more readable I would assume for someone who tries to interpret this for the first time:

([A-Za-z0-9]{1}[A-Za-z0-9\-]{19})\-([A-Za-z0-9]{12})

So, at least, in the first part, we know it is only for character 1. Then, we have another filter for the next 19 characters.

Or:

([A-Za-z0-9]{1}[A-Za-z0-9\-]{19})-([A-Za-z0-9]{12})

...if we ignore the \ which is only there to make sure the - is interpreted ok.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform