我已经学习了大约3周的Java。我看到如下的陈述
String str="I am a Member of MU";
str=str.replaceFirst("(?i)m", "");
基本上,上述语句的功能是替换(删除)第一个“m”忽略的情况。在我看来,“?i”是某种忽略角色情况的算子。任何人都可以向我解释如何使用这个“?i”?我无法找到“?i”的详细语法。谢谢
它是每个lngo's link的“特殊构造”
(?idmsuxU-idmsuxU) - Nothing, but turns match flags i d m s u x U on - off
这意味着在你的情况下
(?i) matches nothing, but turns on flag i (case insensitive).
匹配任何东西都很重要,这样你就不会只更换m
。