Tapatalk

Help with Selective Find and Replace

Help with Selective Find and Replace

74
Advanced UserAdvanced User
74

Sep 08, 2005#1

I need help. I have a macro created to go through a file and replace any acronym with a processing instruction. This works fine, but the problem is I need this not to replace the acronyms inside of frame tags or title tags, and most importantly not inside of another processing instruction.

Sample Text:
<?FRAME ID='2-2.2' TITLE='2.2 ABCD SYSTEM OVERVIEW (CONTINUED)' SHOWNO='Y' NEXT='2-2.2.1'><?BUTTON POS='12' SHOW='Y' LABEL='Acronyms' TYPE='FRAME' LINK='y_acronym.sgm!4-80' BITMAP='N' DESC='List of Acronyms'>

<para0><title>2.2 ABCD SYSTEM OVERVIEW (CONTINUED).</title>
<para><paratext>The ABCD can be described using two levels of building blocks: components and subsystems. The smallest building block is at the component level. There are five classes of components:</paratext></para>
<Randlist>
<item>&bull; <symbol>Owens and McNabb</symbol></item>
<item>&bull; <symbol>Owens and McNabb</symbol></item>
<item>&bull; <symbol>Owens and McNabb</symbol></item>
<item>&bull; <symbol>Owens and McNabb</symbol></item>
<item>&bull; <symbol>Owens and McNabb</symbol></item>
<item>&bull; <symbol>Owens and McNabb</symbol></item>
</Randlist>

<para><paratext>Owens and McNabb haven't been on speaking terms throughout the preseason, but the All-Pro wide receiver said Tuesday in an interview on ESPN that he plans to talk to McNabb before Philadelphia's season opener at Atlanta on Monday night.</paratext></para>
<Randlist>
<item>&bull; <symbol><?HOTSPOT color="blue" linktype="message" HREF="!ABCD and Display Subsystem.txt" TITLE="ABCD and Display Subsystem"?>ABCD and Display Subsystem (ABCD)<?/hotspot></symbol></item>
<item>&bull; <symbol><?HOTSPOT color="blue" linktype="message" HREF="!ABCD Data Subsystem.txt" TITLE="ABCD Data Subsystem"?>ABCD Data Subsystem (ABCD)<?/hotspot></symbol></item>
<item>&bull; <symbol><?HOTSPOT color="blue" linktype="message" HREF="!ABCD Subsystem.txt" TITLE="ABCD Subsystem"?>ABCD Subsystem (ABCD)<?/hotspot></symbol></item>
</Randlist>
</para0>

Script using:
InsertMode
ColumnModeOff
HexOff
UnixReOn
Top
Find RegExp "Alphabet Soup [(]ABCD[)]"
Replace All "<?HOTSPOT color="violet" linktype="message" href="&abcd;" POPUP="1">ABCD<?/HOTSPOT>"

The script traverses through the file and will replace all instances of the acronym, but I need it to be selective. Either someway exclude certain tags (<frame>, <title>) or tell it only to do this action within certain tags (<paratext>. <symbol>).

This is only one acronym, in the actual script there are more than 400.

Your help on this is greatly appreciated.

Thanks, Max

6,693588
Grand MasterGrand Master
6,693588

Sep 15, 2005#2

Within certain tags is a good idea. Try this macro:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Loop
Find RegExp "<paratext>[~<]+</paratext>"
IfFound
StartSelect
Find "your search text"
Replace All SelectText "your replace text"
EndSelect
Else
ExitLoop
EndLoop
Top
Loop
Find RegExp "<symbol>[~<]+</symbol>"
IfFound
StartSelect
Find "your search text"
Replace All SelectText "your replace text"
EndSelect
Else
ExitLoop
EndLoop
Top
UnixReOn

Remove the last red command, if you use regular expression in UltraEdit style by default instead of Unix style - see Advanced - Configuration - Find - Unix style Regular Expressions. UnixReOn/UnixReOff modifies this setting.

Also possible is:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Loop
Find RegExp ">[~<]+"
IfFound
StartSelect
Find "your search text"
Replace All SelectText "your replace text"
EndSelect
Else
ExitLoop
EndLoop
Top
UnixReOn

This macro will select always any text between two tags (including line ending characters), but not inside a tag. Disadvantage of this macro is, that it will do it also in the <title>...</title> area. If you can set the cursor after the </title> tag, for example with an initial find from top, you can use this one.

Both macros are not working for text with < inside it. (In HTML a < in normal text should be always expressed by the entity.) If your text contains <, you can use * instead of [~<]+, but this will not work for text which is spread over multiple lines.
Best regards from an UC/UE/UES for Windows user from Austria

74
Advanced UserAdvanced User
74

Sep 15, 2005#3

This is great! Thank you for the help.

Do you think it's possible to run this application as a "replace in files"?

Thanks, Max

6,693588
Grand MasterGrand Master
6,693588

Sep 16, 2005#4

No, replace in files can't be used. You have to open all files where you want to replace it and run this macro on all open files.

You can do that with the method described at How do you run a Macro on open files?

Or use this faster method, which saves and closes every file after modification by your macro until no named file is open anymore. This macro cannot be used for new files, which are not saved once.

Loop
IfNameIs ""
ExitLoop
EndIf
PlayMacro "case-sensitive name of the replace macro"
CloseFile Save
EndLoop
Best regards from an UC/UE/UES for Windows user from Austria