Java I';I’我在努力学习正则表达式

Java I';I’我在努力学习正则表达式,java,pattern-matching,metacharacters,Java,Pattern Matching,Metacharacters,1.基于此代码 有人能解释一下这是什么吗 while (matcher.find()) { console.format("I found the text" + " \"%s\" starting at " + "index %d and ending at index %d.%n", matcher.group(), matcher.start(), matcher.end()); found =

1.基于此代码

有人能解释一下这是什么吗

while (matcher.find()) {
        console.format("I found the text" + " \"%s\" starting at " +
        "index %d and ending at index %d.%n",
        matcher.group(),
        matcher.start(),
        matcher.end());
        found = true;
}
我只知道
%s
代表字符串

2.关于元字符,有什么解释吗

\%s\”
表示您希望在两个引号之间放置一个字符串,例如,结果可能是:

I found the text "some string"
//""-------------^           ^
// %s             ^_________^
%s
用于字符串,如果要使用数字,可以使用
%d

的引用应该是“<强> >如何?< /强”可以使用反斜杠<代码> \“/CODE >,所以请考虑我有一个字符串,包含这样的引用:代码> hello”Word“< /Cord>”如何将其作为java中的字符串:

String string = "Hello "World"";  //<<------- this is an error syntax
看看

\%s\“
意思是你想在两个引号之间放一个字符串,例如,结果可能是:

I found the text "some string"
//""-------------^           ^
// %s             ^_________^
%s
用于字符串,如果要使用数字,可以使用
%d

的引用应该是“<强> >如何?< /强”可以使用反斜杠<代码> \“/CODE >,所以请考虑我有一个字符串,包含这样的引用:代码> hello”Word“< /Cord>”如何将其作为java中的字符串:

String string = "Hello "World"";  //<<------- this is an error syntax
查看
字符串中的百分号(
%
)与字母b、c、d、e、f、s一起用于限制要显示的字符数

%b
-布尔值
%c
-字符
%d
-整数
%e
-科学记数法
%f
-浮点数(双精度,浮点)
%s
-字符串

例如:

String text = "abcdef";
System.out.printf("%.3s", text); //output:  abc

字符串中的百分号(
%
)与字母b、c、d、e、f、s组合用于限制要显示的字符数

%b
-布尔值
%c
-字符
%d
-整数
%e
-科学记数法
%f
-浮点数(双精度,浮点)
%s
-字符串

例如:

String text = "abcdef";
System.out.printf("%.3s", text); //output:  abc


%s
一个格式化程序字符,用于基于格式的打印,这与正则表达式本身无关。API。
%s
一个格式化程序字符,用于基于格式的打印,这与正则表达式本身无关。这两个反斜杠是干什么的?它们转义引号(
)。你可以删除它们,然后你就会看到你得到了什么错误。@Jérôme你会得到
java.lang.RuntimeException:不可编译的源代码-不是一句话
非常感谢@YCF\L你能给我推荐一些我可以从中学习特定主题的网站吗?这两个反斜杠是干什么的?它们不带引号(
)。你可以删除它们,你会看到你得到了什么错误。@Jérôme你会得到
java.lang.RuntimeException:不可编译的源代码-不是一句话
非常感谢@YCF_L你能给我推荐一些我可以学习特定主题的网站吗?顺便说一句,它是“%.3s”。无论如何,谢谢。顺便说一句,它是“%.3s”。无论如何,谢谢。