2

我的文件内容如下

abcd-12=jksjd-jkkj
xyzm-87=hjahf-tyewg-iuoiurew
zaqw-99=poiuy-12hd-jh-12-kjhk-4rt45

我想用下划线符号替换'='之后的连字符,即等式的RHS。

No of hypenated terms are variable in the lines, it can be 3 or 4 or 5

如何对整个文档执行此操作。左侧应完好无损。

我想要的结果是:

abcd-12=jksjd_jkkj
xyzm-87=hjahf_tyewg_iuoiurew
zaqw-99=poiuy_12hd_jh_12_kjhk_4rt45
4

3 回答 3

3

一种选择是在正则表达式模式下进行以下查找和搜索:

Find:    = ([^-]+)-([^-]+)$
Replace: = $1_$2

演示

这里的策略是匹配并捕获出现在等式的 RHS 上的连字符的两半。然后,用下划线分隔的两半替换。

编辑:

如果 RHS 确实有四个连字符,则使用:

Find:    = ([^-]+)-([^-]+)-([^-]+)-([^-]+)$
Replace: = $1_$2_$3_$4
于 2019-11-11T12:47:44.063 回答
2

这将一次性替换任意数量的连字符:

  • Ctrl+H
  • 找什么:(?:=|(?!^)\G).*?\K-
  • 用。。。来代替:_
  • 检查 环绕
  • CHECK 正则表达式
  • 取消选中 . matches newline
  • Replace all

解释:

(?:             # non capture group
    =           # equal sign
  |             # OR
    (?!^)       # negative lookahead, make sure we are not at the beginning of a line
    \G          # restart from last match position
)               # end group
.*?             # 0 or more any character but newline, not greedy
\K              # forget all we have seen until this position
-               # a hyphen

屏幕截图(之前):

在此处输入图像描述

屏幕截图(之后):

在此处输入图像描述

于 2019-11-11T16:14:35.787 回答
0

搜索:

(=[^-\r\n]+)-

用。。。来代替:

\1_

注意:重复搜索和替换,直到不再进行替换。

在这里测试。

于 2019-11-11T13:03:27.910 回答