java中带回调函数的字符串替换,类似js中的replace(rgExp,function)
https://blog.csdn.net/weixin_33834075/article/details/91599852
import java.util.regex.Matcher;
import java.util.regex.Pattern; public class TestRegExp {
public static void main(String[] args) {
String str = "insert into @@table(@@dataAsIn1sertKeys:aaa.aa) values( @@dataAsInsertValues )";
System.out.println(replaceString(str));
} public static String replaceString(String str) {
Pattern pattern = Pattern.compile("@@[0-9a-zA-Z:.]+");
Matcher m = pattern.matcher(str);
if (!m.find()) {
return str;
} StringBuffer sb = new StringBuffer();
int index = 0;
do {
index++;
String group0 = m.group(0);
System.out.println(group0);
m.appendReplacement(sb, "aaaa_" + index + "_" + m.group(0));
} while (m.find()); m.appendTail(sb);
return sb.toString();
} }
java中带回调函数的字符串替换,类似js中的replace(rgExp,function)的更多相关文章
- LoadRunner中自定义C函数实现字符串替换
.在globals.h 中定义一个函数ReplaceStr,实现字符串的替换: int ReplaceStr(char* sSrc, char* sMatchStr, char* sReplaceSt ...
- Java中的回调函数学习
Java中的回调函数学习 博客分类: J2SE JavaJ# 一般来说分为以下几步: 声明回调函数的统一接口interface A,包含方法callback(); 在调用类caller内将该接口设置 ...
- Java中的回调函数学习-深入浅出
Java中的回调函数一般来说分为下面几步: 声明回调函数的统一接口interface A.包括方法callback(); 在调用类caller内将该接口设置为私有成员private A XXX; 在c ...
- Easyui中 alert 带回调函数的 消息框
带回调函数的 消息框: $.messager.alert({ title:'消息', msg:'电话号码 只能是数字!', icon: 'info', width: 300, top:200 , // ...
- 理解与使用Javascript中的回调函数 -2
在javascript中回调函数非常重要,它们几乎无处不在.像其他更加传统的编程语言都有回调函数概念,但是非常奇怪的是,完完整整谈论回调函数的在线教程比较少,倒是有一堆关于call()和apply() ...
- js回调函数,字符串,数组小析
(一)回调函数:是指通过函数参数传递到其他代码的,某一块可执行代码的引用.这一设计允许了底层代码调用在高层定义的子程序.在抖动函数中,回调函数用于在实现一些功能之后采取的另外的措施,比如div,照片抖 ...
- PHP中的回调函数和匿名函数
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
- 理解和使用 JavaScript 中的回调函数
理解和使用 JavaScript 中的回调函数 标签: 回调函数指针js 2014-11-25 01:20 11506人阅读 评论(4) 收藏 举报 分类: JavaScript(4) 目录( ...
- C中的回调函数
C语言中应用回调函数的地方非常多,如Nginx中: struct ngx_command_s { ngx_str_t name; ngx_uint_t type; char *(*set)(ngx_c ...
- 理解javascript中的回调函数(callback)
以下内容来源于:http://www.jb51.net/article/54641.htm 最近在看 express,满眼看去,到处是以函数作为参数的回调函数的使用.如果这个概念理解不了,nodejs ...
随机推荐
- C# 时间各种格式
1.1 取当前年月日时分秒 currentTime=System.DateTime.Now; 1.2 取当前年 int 年=currentTime.Year; 1.3 取当前月 int 月=curre ...
- gridfs + nginx + mongodb 实现图片服务器
项目预览网址 : http://trans.waibaobao.cn/file/pics 安装:前提安装mongodb 作为文件储存库 1)nginx-gridfs安装 a.安装所用依赖包 yum - ...
- 项目day1 -- vscode远程连接云服务器
刚学完go的语法,本来想着找个小项目试试手,发现大佬们都是vscode ssh到云服务器上做开发的.正好看到阿里云的学生认证后可以白嫖,就先嫖了个试试手 跟着各大教程简单配置了一下阿里云,安装vsco ...
- window.location.href 用法总结
想做好前端,这几种用法一定要了解: 在做网页前端的时候会经常用到JavaScript其中window.location.href用得非常多: 其中最常用的有windows.location.href= ...
- 深入理解webpack的chunkId对线上缓存的思考(转载)
转载自https://juejin.cn/post/6844903924818771981#heading-6 作者:Kimm 想必经常使用基于webpack打包工具的框架的同学们,无论是使用Rea ...
- Jest - Testing Asynchronous
When we test asynchronous, we use Axios to get the response. install the Axios npm i axios Cause we ...
- MobilePBRLighting优化思路2
在最近的研究工作中,进一步对移动端PBRLighting进行了优化,以下是一些优化截图,由于后续整理文章使用: PBRLighting(未开启伽马矫正): MobilePBRLighting(高质量版 ...
- vue-cli 根据不同的环境打包
根据项目需要,通过vue-cli中的npm run build 打包到不同的环境,例如测试环境,预发布环境,线上环境,根据process.env分别进行接口的调用 vue-cli 中build中bui ...
- Java编写1到100质数之和
int sum = 0; int k = 2; // 找出1-100的质数之和 for (int i = 2; i <= 100; i++) { // i值为2,质数为除去1和自身整除的数 j初 ...
- 4、Hadoop初识