简体   繁体   English

不区分大小写的字符串过滤器

[英]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? 特别是{"+word.length()+"}做了什么,它背后的逻辑是什么,我在哪里可以阅读更多关于它的内容?

Curly braces here mean that number of symbols, for example {4} means exactly four symbols. 这里的花括号表示符号数,例如{4}表示恰好四个符号。 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. 您也可以指定{2-4},例如,表示与给定模式匹配的字母数的间隔。 Hope this helps. 希望这可以帮助。

You are misreading the parameters... this: 你误读参数......这个:

"[a-zA-Z]{"+word.length()+"}" “[1 - ZA-Z] {” + word.length()+ “}”

is the same as 是相同的

    "[a-zA-Z]{" // this is a string

+

    word.length() // this is getting an integer( is the length of the string word)

+

    "}" //another litt. string.

so you are technically concatenating 2 strings and putting in the middle a number... 所以你在技术上连接2个字符串并在中间插入一个数字......

just that 只是

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM