可以使用Java字符串。indexOf()是否将正则表达式作为参数处理?
我想在Java字符串中捕获特定正则表达式的索引。该字符串可以用单引号或双引号括起来(有时没有引号)。如何使用Java捕获该索引
例如:
capture String --> class = ('|"|)word('|"|)
你可以在下面搜索框中键入要查询的问题!
我想在Java字符串中捕获特定正则表达式的索引。该字符串可以用单引号或双引号括起来(有时没有引号)。如何使用Java捕获该索引
例如:
capture String --> class = ('|"|)word('|"|)
# 1 楼答案
基于@Andreas Dolk的答案,包装在复制粘贴就绪代码中:
# 2 楼答案
这是一个两步的方法。首先,为您的模式找到一个匹配项,然后(第二)使用
Matcher#start
获取匹配字符串在内容字符串中的位置# 3 楼答案
否
Check source code for verification
解决方法: 这不是标准的做法,但你可以使用它得到结果
更新:
或者