If you have a use case like email address where it formatting in UUID pattern. Here is the regular expression that can help you to filter among them.
String pattern = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}@[A-Za-z0-9.-]+(\\.[A-Za-z]{2,})$";
Above regular expression have two part, first part are use to determine uuid pattern while second part is used to determine email. Let’s break it into details.
[0-9a-f]{8}-
This mean allow any numbers or character from 0 – 9 or a – f with total 8 character with additional hyphen (-)
[0-9a-f]{4}-
This mean allow any numbers or character from 0 – 9 or a – f with total 4 character with additional hyphen (-)
[0-9a-f]{12}+
This mean allow any numbers or character from 0 – 9 or a – f with total 12 character with additional plus (+) sign means match 0 or more times.
@[A-Za-z0-9.-]+
This mean allow an at (@) sign and any numbers or character upper or lower case from 0 – 9 or a – z with additional dot (.) and hyphen (-) sign.
plus (+) sign means match 1 or more times.
(\\.[A-Za-z]{2,})$
Within the parentheses, this mean allow a dot (.). First backslash is use for java escape key, second backslash is to turn on the special character function in regular expression for (dot). Then match with any character upper or lower case from a – z with {2,} at least 2 characters or more. dollar ($) sign (-) means match at the end.
Example
5f9900e2-768c-99c4-z81t-701e5d2468b@codeomitted.com True 5F9900E2-768C-99C4-Z81T-701E5D2468B@codeomitted.com False 5f9900e2-768c-99c4-z81t-701e5d2468b@codeomitted.a False 5f9900e2-99c4-z81t-701e5d2468b@codeomitted.com False
More references
^ Start with match $ End with match ! Not match . Match single of any value | Condition or, either match with pre-condition or post-condition \ Escape special character function () Grouping the condition [] Match any single within bracket [^] Match any single excepts within bracket ? Match 0 - 1 times + Match 1 - more times * Match 0 - more times {n} Match specific times {n,} Match nth - more times {,n} Match 0 - max times nth {n,m} Match nth min - mth max times