Reputation: 241
I have a few strings and I need some help with constructing Regex to match them.
The example strings are:
AAPL10.XX1.XX2
AAA34CL
AAXL23.XLF2
AAPL
I have tried few expressions but couldn't achieve exact results. They are of the following:
[0-9A-Z]+\.?[0-9A-Z]$
[A-Z0-9]*\.?[^.]$
Following are some of the points which should be maintained:
Please ask me for any clarification.
Upvotes: 0
Views: 37
Reputation: 163362
You can write the pattern as:
^[A-Z\d]+(?:\.[A-Z\d]+){0,2}$
The pattern matches:
^
Start of string[A-Z\d]+
Match 1+ chars A-Z or a digit(?:\.[A-Z\d]+){0,2}
Repeat 0 - 2 times a .
and 1+ chars A-Z or a digit$
End of stringUpvotes: 2