ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 ``` /** * <b>方法描述:</b> 字符串正则表达式替换 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-08 18:16:53 <br/> * * @param source * 入参|输入字符串|{@link java.lang.String} * @param regex * 入参|正则表达式|{@link java.lang.String} * @param replacement * 入参|替换字符|{@link java.lang.String} * @param newString * 出参|新字符串|{@link java.lang.String} * @return -1 异常<br/> * 1 成功<br/> */ @Component(label = "字符串正则表达式替换", style = "判断型", type = "同步组件", comment = "输入字符匹配正则表达式,替换成新字符串", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-08 06:16:53") @InParams(param = { @Param(name = "source", comment = "输入字符串", type = java.lang.String.class), @Param(name = "regex", comment = "正则表达式", type = java.lang.String.class), @Param(name = "replacement", comment = "替换字符", type = java.lang.String.class) }) @OutParams(param = { @Param(name = "newString", comment = "新字符串", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "1", desp = "成功") }) public static ResultBase P_replacePattern(String source, String regex, String replacement) { try { return ResultBase.newSuccessResult(StringUtil.replacePattern( source, regex, replacement)); } catch (Exception e) { AppLog.error("字符串正则替换异常:输入字符串:{},表达式:{},替换字符:{}", source, regex, replacement); AppLog.error(e); } return ResultBase.newExceptionResult("TPTS1015", "参数错误,不能替换"); } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/39/fa/39fac4d5249d5f7543efe1cb4e64bf8a_1869x889.png) # 参数说明及示例 ## 入口参数 输入字符串:输入字符串,示例: `"你好,世界22333"` 正则表达式:输入正则表达式,示例: `"\\d+"` 替换字符:输入要替换的新字符,示例: `"b"` ## 出口参数 新字符串:输入字符匹配正则表达式,替换成新字符串,示例: `__INNER__["result"]`