小编ian*_*nuk的帖子

正则表达式的部分匹配

在NFA中,很容易使所有先前非最终状态接受使其匹配给定语言的所有子串的语言.

在Java regex引擎中,有没有办法找出字符串是否是与给定正则表达式匹配的字符串的起始子字符串?

regexX ="任何开始",regexA - 任何给定的正则表达式

"regexXregexA"结果表达式匹配匹配"regexA"的所有子字符串:

例:

regexA = a*b
Run Code Online (Sandbox Code Playgroud)

"a"匹配

"regexXa*b"
Run Code Online (Sandbox Code Playgroud)

因为它是"ab"(和"aab")
编辑的开头:

由于有些人仍然不理解,这里是这个问题的程序测试:

import java.util.regex.*;
public class Test1 {
    public static void main(String args[]){
       String regex = "a*b";
       System.out.println(
       partialMatch(regex, "aaa");
       );
     }
public boolean partialMatch(String regex, String begining){
//return true if there is a string which matches the regex and    
//startsWith(but not equal) begining, false otherwise 
}
}
Run Code Online (Sandbox Code Playgroud)

结果是真的.

java regex

5
推荐指数
1
解决办法
1941
查看次数

标签 统计

java ×1

regex ×1