Regular Expression Knowledge Exercise

Please generate a regular expression string that will convert an input string from LTVCL-9-9-9-9-9-9 to LTVCL-9-9-9-A-9-9 , where 9 represents any value from 0 to 999.

Also Note: the “A” is just a string of “A”.

From String

To String

LTVCL-9-9-9-9-9-9 LTVCL-9-9-9-A-9-9
LTVCL-01-8-111-65-11-23 LTVCL-01-8-111-A-11-23
LTVXL-01-8-111-65-11-23 LTVXL-01-8-111-65-11-23
LTVCL-03A-6-22-165-311-3 LTVCL-03A-6-22-A-311-3
LTVCL-1-1-1-11-23 LTVCL-1-1-1-11-23
LTVCL-01-8-11-5-1-23 LTVCL-01-8-11-A-1-23

Regular Expression (RegEx) string result:

^LTVCL[-][a-zA-Z0-9]{1,3}[-][a-zA-Z0-9]{1,3}[-][a-zA-Z0-9]{1,3}[-]([0-9]{1,3})[-][a-zA-Z0-9]{1,3}[-][a-zA-Z0-9]{1,3}$

You can verify resulted regular expression online. Below screenshot shows that regular expression mentioned above gives expected result as per “To String” column.

Regular Expression result match online

Regular Expression result matches online

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!