0

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.

Toto
  • 89,455
  • 62
  • 89
  • 125
Greesha
  • 1
  • 1
  • 1

4 Answers4

2

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

Tony Miller
  • 9,059
  • 2
  • 27
  • 46
  • Doesn't work, because Notepad++ does not support anything besides BRE. – Spencer Rathbun Feb 20 '12 at 18:37
  • why are you putting the "space" inside a character class? It's just one character, instead of [ ], you should use \s. – Scott Weaver Feb 20 '12 at 19:37
  • I used space in brackets because I was quickly using the NotePad++ regular expression syntax help and didn't see a whitespace character class. It does have one, of course. – Tony Miller Feb 21 '12 at 19:52
1

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

and replace by : \1F5.0

Toto
  • 89,455
  • 62
  • 89
  • 125
  • @TonyMiller: Just a little bit simpler. But yours may work better depending on cases. – Toto Feb 20 '12 at 18:36
  • As noted on Tony's answer, Notepad++ does not support Extended syntax. Most notably `()` groupings. – Spencer Rathbun Feb 20 '12 at 18:43
  • @SpencerRathbun: did you try it? Of course, Notepad++ supports grouping. – Toto Feb 20 '12 at 18:52
  • @M42 Hmm, it seems that it *does* support groupings. Last I'd checked it did not. However, it [has some odd corners](http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Unsupported_Regex_Operators) when using groupings. – Spencer Rathbun Feb 20 '12 at 19:18
  • This isn't better than Tony's regex. (mistaken character class notwithstanding). With real world regex, it's a good idea to 1) anticipate some variability in your data so you don't match facerolls '835704iuretohwiuhX.0.E.F500.0.2340987502349875.284507923', and 2) anchor the regex with some known structure, like the 'G1' in the data. – Scott Weaver Feb 20 '12 at 19:43
0

Hit ctrl+h in the first field put what you wanna find, in the second put in what you wanna replace it with.

JKirchartz
  • 17,612
  • 7
  • 60
  • 88
-2

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.

Spencer Rathbun
  • 14,510
  • 6
  • 54
  • 73
  • 1
    Sed? Really? Text editors are just FINE for search/replace, that's kinda what they do, after all, it's just that some are better than others. – Scott Weaver Feb 20 '12 at 19:48
  • @sweaver2112 Straight search/replace isn't a problem. Once you move into regex, you start hitting inconsistencies. And people try to "parse" their text with a single regex. And wonder why they match things they didn't expect. And try to include logic constructs in the replacement. I direct you to an [example of where this can lead](http://stackoverflow.com/a/1732454/724357). Neither `sed` nor `macros` really fits where this leads, I was just giving options ( go with the scripts...) – Spencer Rathbun Feb 20 '12 at 20:17
  • 1
    -1. OP explicitly requested via NotePad++. If you're going to answer, answer what is asked for first, then offer alternatives. – Tony Miller Feb 21 '12 at 19:54