davek:
--------------------------------------------------------------------------------
I have downloaded PSPad to perform automatic edits to programs which run
machine tools where I work. 

I need to make a macro using search and replace to take all one or two digit
numbers after a "T" and move them after the next occurrence of "M6" (with a
"T").

Example

_T77_
G90G55G17G0X33.138Y36.944
G43Z25.H76S300M3
Z25.M8
G1Z-17.5F1500.
X34.879Y27.071F90.
_M6_

needs to end up as

_T77_
G90G55G17G0X33.138Y36.944
G43Z25.H76S300M3
Z25.M8
G1Z-17.5F1500.
X34.879Y27.071F90.
_M6T77_

The text in between the T** could be pages long. 

There will be no other "T"s and no occurrences of "M" without a "6" after. 

No lower case letters

In word I did this with

find       <T(*)(*)>*M6
replace    ^&T\1\2

The * referred to all the intervening text nicely.

I can't seem to do this with regular expressions. Help me Mr. Wizard.
--------------------------------------------------------------------------------


Hi,
You can't do such conversion using the built in PSPad functionality, but you can
use a script which performs a regular expression replacement via javascript.
You can try the following one and adjust it as needed (Copy the source to a
file, e.g.
...\PSPad\Script\JScript\test_js.js
and possibly enable WSH scripting in Settings: System integration
You can call the script from the Scripts menu, or with a shortcut (adjustable in
the script - Init)

The pattern also requires that "M6" is originally at the end of the line or the
whole file; if it isn't the case in your data, just remove (?=(?:
)|$) but in
this case the repeated calls of this replacement will probably corrupt the data
and copy the T.. codes across the original blocks.

You should test the script carefully, whether it suits your needs - as a
javascript, it might have problems on large files; unicode characters over the
current ANSII codepage are lost with such replacement.

hth,
   vbr



cite:
--------------------------------------------------------------------------------
//// ... PSPad\script\JScript\copy_T_nr.js /// 
var module_name = "copy_T_nr"; 
var module_ver = "1";

function copy_T_nr(){
if (editorsCount()<1){return;} // quit if no text window is open 
var actEd = newEditor(); 
actEd.assignActiveEditor(); 
var inputTxt = actEd.text(); // get the whole text
var outputTxt = inputTxt.replace(/(T\d{1,2})((?:.|\n)*?)(M6(?=(?:
)|$))/g,
"$1$2$3$1");
actEd.text(outputTxt); // set the modified text content 
}

function Init(){
addMenuItem("copy T nr", "", "copy_T_nr", "Ctrl+Alt+Shift+Q");// labels and
shortcuts can be modified
}

--------------------------------------------------------------------------------


-- 
<http://forum.pspad.com/read.php?2,59606,59608>
PSPad freeware editor http://www.pspad.com

Odpovedet emailem