Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用正则表达式在字符串中查找不同的字符序列_Java_Regex - Fatal编程技术网

Java 使用正则表达式在字符串中查找不同的字符序列

Java 使用正则表达式在字符串中查找不同的字符序列,java,regex,Java,Regex,例如: 如果我们有一个字符串s1=“abcde”s2=“abd” 查找s1、s2中出现的“ad”。。这里的发生次数总的来说是2 关于java中的正则表达式代码,有人能帮我吗。。。请..您可以使用indexOf(String str)然后indexOf(String str,int from index)来查找所有出现的情况及其位置。请查看用于文本搜索的knuth-pratt-morris算法字符串中的任意位置都可以出现“a”和“d”吗?还是它们总是出现在开始/结束处?字符串是否可以包含多个a后跟

例如:
如果我们有一个字符串s1=“abcde”s2=“abd”
查找s1、s2中出现的“ad”。。这里的发生次数总的来说是2


关于java中的正则表达式代码,有人能帮我吗。。。请..

您可以使用
indexOf(String str)
然后
indexOf(String str,int from index)
来查找所有出现的情况及其位置。

请查看用于文本搜索的knuth-pratt-morris算法

字符串中的任意位置都可以出现“a”和“d”吗?还是它们总是出现在开始/结束处?字符串是否可以包含多个a后跟d?