Reputation: 365
I wanted to match 2 groups using regex from the following Strings:
LyraCalSWC20161203.png
LyraL4C20180302.png
This is the regex I proposed - Lyra([A-Za-z]{3,6})+(\\d{8}).*
It should match 2 groups. The first one being L4C
or CalSWC
and the second group the date string which is 8 numbers.
I can get one group to work e.g) LyraL4C(\\d{8}).*
but not the one to handle both variations.
Any help much appreciated
Thanks
Upvotes: 0
Views: 38
Reputation: 21995
You might want to use the generic \w
selector picking all the words characters to match both versions of your samples
^Lyra(\w{3,6})(\d{8})\.png$
Escaped for java ^Lyra(\\w{3,6})(\\d{8})\\.png$
Upvotes: 2
Reputation: 54168
Lyra([A-Za-z]{3,6})+(\\d{8}).*
is pretty good, but you miss that L4C
contains not only letters, but also numbers. {3,6}
so don't need to use +
So you need Lyra([A-Za-z0-9]{3,6})(\\d{8}).*
Upvotes: 3