java indexof 正则_Java String.indexOf()可以将正则表达式作为参数处理吗?

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-24 05:17   33   0

没有。

WorkAround:

它不是标准的做法,但你可以使用这个结果。

更新:

CharSequence inputStr = "abcabcab283c";

String patternStr = "[1-9]{3}";

Pattern pattern = Pattern.compile(patternStr);

Matcher matcher = pattern.matcher(inputStr);

if(matcher.find()){

System.out.println(matcher.start());//this will give you index

}

要么

Regex r = new Regex("YOURREGEX");

// search for a match within a string

r.search("YOUR STRING YOUR STRING");

if(r.didMatch()){

// Prints "true" -- r.didMatch() is a boolean function

// that tells us whether the last search was successful

// in finding a pattern.

// r.left() returns left String , string before the matched pattern

int index = r.left().length();

}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP