简体   繁体   English

记事本++范围替换

[英]Notepad++ range replace

I'm trying to replace several hundred different values with a single value:(example)= 我正在尝试用单个值替换数百个不同的值:((示例)=

Line 115242: birth_date="850.1.1" 第115242行​​:birth_date =“ 850.1.1”

Line 115317: birth_date="851.1.1" 行115317:birth_date =“ 851.1.1”

Line 115392: birth_date="855.1.1" .... etc. 115392行:birth_date =“ 855.1.1” ....等

I want to replace each one with: birth_date="451.1.1" 我要替换为:birth_date =“ 451.1.1”

Is there a quick and easy way to do it with the replace function? 有使用替换功能进行操作的快速简便的方法吗? (assume I don't know any of terms/acronyms/jargon) (假设我不知道任何术语/缩写/行话)

Essencially, I'm trying to replace the range of values between: 从本质上讲,我正在尝试替换以下范围内的值:

birth_date="600.1.1" and birth_date="900.1.1" birth_date =“ 600.1.1”和birth_date =“ 900.1.1”

This is in python 这是在python中

You might be able to leverage regular expressions. 您也许可以利用正则表达式。 The range limitation makes it more difficult, but with 2 different replaces, I think we can manage it. 范围限制使它变得更加困难,但是我认为可以通过2种不同的替换方法来管理它。 (The complication comes from the fact you don't want to replace values like 900.4.3 .) (复杂的原因是您不想替换900.4.3值。)

  1. Back up your file, just to be safe. 为了安全起见,请备份您的文件。
  2. Open the Replace dialog, and change Search Mode to "Regular expression". 打开“替换”对话框,然后将“搜索模式”更改为“正则表达式”。
  3. Enter birth_date="[678]\\d\\d\\.\\d+\\.\\d+" in "Find what:". 在“查找内容:”中输入birth_date="[678]\\d\\d\\.\\d+\\.\\d+" ”。
  4. Enter birth_date="451.1.1" in "Replace with:" 在“替换为:”中输入birth_date="451.1.1"
  5. Press Replace All. 按全部替换。
  6. Change "Find what:" to birth_date="900\\.1\\.1" . 将“查找内容:”更改为birth_date="900\\.1\\.1"
  7. Press Replace All. 按全部替换。

Then check to make sure it did what you wanted. 然后检查以确保它满足您的要求。 A differencing tool might be helpful there. 差异工具可能会有所帮助。 (You can compare the modified file with the back up.) (您可以将修改后的文件与备份进行比较。)

The two different regexes are necessary because of the range. 由于范围的原因,两个不同的正则表达式是必需的。 The first one catches anything starting with 6 , 7 , or 8 plus any two numeric digits. 第一个捕获任何开始67 ,或8加上任何两个数字。 The second handles the last value we want to replace, which is the first of the 900 values. 第二个处理我们要替换的最后一个值,这是900值中的第一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM