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

这篇博客介绍了如何利用Java的Pattern和Matcher类来匹配字符串中的特定数字模式,例如连续的三位数字。通过示例代码,展示了如何找到匹配的数字并获取其在原始字符串中的起始索引。这对于处理和解析含有特定格式的数据字符串非常有用。
摘要由CSDN通过智能技术生成

没有。

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();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值