user119680
user119680

Reputation: 531

regular expression to match first first three letters of a string that must be 12 chars long and uppercase

I need some pointers with some regex voodoo - I just don't use them enough day to day to be familiar with them.

I'm processing a string containing multiple words and need to look for a reference number.

The ref number is in the format LCSYK89HE4W4 . 'LCS' is always constant, the Ref is always 12 chars long. The rest of the ref is made up from random uppercase alphanumeric chars.

Examples:

LCSJKIIU786T
LCS5YU87TFR4
LCSKIJ5R67DE

Any pointers would be much appreciated.

Thanks Sam

Upvotes: 3

Views: 1961

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476554

Use the following regex

LCS[0-9A-Z]{9}

Using this string however, it happens that a line containing additional characters before and after will not be rejected. If the string should begin and end with the ref number, use

^LCS[0-9A-Z]{9}$

You can test the regex here http://phpregextester.com/ (use /LCS[0-9A-Z]{9}/)

Upvotes: 5

Related Questions