-1

我想找到从 4000 到 4999 的所有数字,并将前导 4 替换为 7。

例如:

4000 -> 7000
4015 -> 7015
4987 -> 7987

我尝试用 替换4\d\d\d\d7\1但没有用。

4

3 回答 3

3

使用正则表达式替换模式搜索\b4(\d{3})\b并替换为。7\1

单词边界确保您不会意外匹配14000或。40000

于 2013-07-10T13:14:57.190 回答
3

搜索(?<!\d)4(\d{3})(?!\d)并替换为7\1

解释

(?<!\d)     # Negative lookbehind: check if there is no digit preceding 4
4           # match 4
(           # start group 1
    \d{3}   # match 3 digits
)           # end group 1
(?!\d)      # Negative lookahead: check if there is no digit following the 3 digits

替换:\1指第 1 组。

在此处输入图像描述

虽然蒂姆的解决方案更好:p

于 2013-07-10T12:58:42.137 回答
1

在下面尝试notepad++

搜索4(\d\d\d)并替换为7\1

于 2013-07-10T13:05:48.000 回答