c语言java转换工具_C语言正则表达式到Java匹配器问题的转换

public static String ReturnBetween(String heap, String startEx, String endEx, boolean include) {

int startPos = 0;

int endPos = heap.length();

String starts = "";

String ends = "";

if (!startEx.equals("^")) {

Pattern regexStart = Pattern.compile(startEx, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

starts = regexStart.matcher(heap).toString();

if (starts.equals("")) {

startPos = -1;

} else {

startPos = heap.indexOf(starts);

}

}

if (startPos == -1) {

return "";

}

if (!endEx.equals("$")) {

Pattern regexEnd = Pattern.compile(endEx, Pattern.CASE_INSENSITIVE | Pattern.DOTALL );

ends = regexEnd.Match(heap, startPos + starts.length()).toString();

if (ends.equals("")) {

endPos = -1;

} else {

endPos = heap.indexOf(ends, startPos + starts.length());

}

}

if (endPos == -1) {

return "";

}

if (!include) {

startPos += starts.length();

}

if (include) {

endPos += ends.length();

}

String result = heap.substring(startPos, endPos);

return result;

}

这是一个C函数,用于获取两个变量之间的字符串,我试图把它转换成Java函数,大部分已经被转换成Java代码。

我已经成功地转换了这个函数。除本部分外:

ends = regexEnd.Match(heap, startPos + starts.length()).toString();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值