Search code examples
javaregexstringfiltercase-insensitive

Case-Insensitive String Filter


This is a line of code I found :

if(!word.matches("[a-zA-Z]{"+word.length()+"}")) return;

Specifically what does {"+word.length()+"} do, what's the logic behind it, and where can I read more about it?


Solution

  • Curly braces here mean that number of symbols, for example {4} means exactly four symbols. Here you specify entire string (inserting the length of it) to consist of small or large latin letters. Also you can specify {2-4} for example, meaning interval of number of letters that match given pattern. Hope this helps.