简体   繁体   中英

Notepad++ Find and Replace syntax, help needed

I am very new to Notepad++ and need a little help with Find and Replace functions. I have a code for CNC machine which looks like this:

G1 X0.625 Z1.242 F500.0
G1 Z0.099 A358.475 F500.0
G1 X0.542 Z1.247 F500.0
G1 Z0.100 A356.949 F500.0
G1 X0.458 Z1.254 F500.0
G1 Z0.102 A355.424 F500.0
G1 X0.375 Z1.263 F500.0

I need to find each line that contains X and replace value of F500.0 to F5.0. What syntax should I use? Thanks in advance.

I think that this will work, but it depends on the variability of your data:

(G1[ ]+X.+[ ]+[A-Z0-9.]+[ ]+)F500\.0

and replace with

\1F5.0

This collects everything to the left of F500.0 (the . is to get a literal period. I put in a literal G1, then spaces, then X followed by anything, then spaces, then word charaters and numbers and period repeated, then finally the F500.0.

I am replacing that with \\1 which is the stuff collected in parentheses followed by F5.0.

Reference: NotePad++ Regular Expression Syntax

Update: Added link to NotePad++ Regular Expression Syntax

Search for : (X.*)F500\\.0

and replace by : \\1F5.0

在第一个字段中按ctrl+h组合您要查找的内容,在第二个字段中按要替换的内容。

Notepad++ uses basic regular expression syntax . So, you are going to have lots of problems trying to use it as a Perl Compatible Regular Expression (PCRE).

The best way to do this is to use a tool that is actually designed for these types of tasks. Sed, or a perl one liner. For example:

sed -i -r 's/(X.*)F500\.0/\1F5.0/g' yourFile

The -i switch is for in place editing, and -r is for extended regex syntax. Of course, setting up sed on windows is irritating.

So, you may have better luck with a small python or perl script. Another choice is a notepad++ macro.

Edit:

As pointed out to me by M42, notepad++ actually does support groupings, kind of .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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