其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

正则表达式怎么全局替换相同格式不同内容?

GG网络技术分享 2025-03-18 16:14 7


问题描述:

比如

        <if test=\"id != null \">

<if test=\"merOrderId != null \">

<if test=\"bankOrderId != null \">

<if test=\"merId != null \">

<if test=\"siteId != null \">

要替换成

<if test=\"id != null and id ! = \'\' \">

<if test=\"merOrderId != null and merOrderId ! = \'\'\">

<if test=\"bankOrderId != null and bankOrderId ! = \'\'\">

<if test=\"merId != null and merId ! = \'\'\">

<if test=\"siteId != null and siteId ! = \'\'\">

查找是 查找 <if test=\".* != null \"> 可以找出所有

但是要替换成什么内容,要怎么写

网友观点:


(?<=(test=\\\"))(.+)(?=!=)
匹配到 id merOrderId bankOrderId

然后把结果存成变量.替换成 result != \'\' and result 就可以了

正则表达式描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串、将匹配的子串替换或者从某个串中取出符合某个条件的子串等.
执行替换还是要写程序的.

(?<)\\d+(?=)

(?<=(test=\\\"))(.+)(?=!=)

这个可以的

使用正则表达式匹配文本时,如何在包含一部分内容的同时,不包含另一部分内容?

例如匹配一段只包含除了HIJK外的其他字母的字符串

标签:

提交需求或反馈

Demand feedback