how to replace numbers, but NOT affecting the numbers between brackets ()

how to replace numbers, but NOT affecting the numbers between brackets ()

2
NewbieNewbie
2

    Jan 12, 2009#1

    I am working on a huge complicated txt file. And I need to put some HTML tags before and after some numbers. But NOT all the numbers should be processed. Those numbers between "(" and ")" should not be tagged.

    For example

    Code: Select all

    Text 1. textA 2. textB ( 1. textC 2. textD) 3. text E
    I want to replace those numbers into a form finally with HTML tags as follow,

    Code: Select all

    Text </br><b> 1. </b> textA </br><b> 2. </b> textB ( 1. textC 2. textD) </br><b> 3. </b> text E
    The text content could be anything (like letters, numbers or punctuation). If I simply replace " 1. " with "</br><b> 1. </b>"that will affect also that "number 1." in brackets ( 1. textC) and turn it into Text </br><b> 1. </b> textA 2. textB (</br><b> 1. </b>. textC 2.textD) 3. text E
    And that's of course NOT I want it to be.

    So, any solution to replace those numbers outside the brackets? Any help would be highly appreciated!

    Besides I would like to ask another question, how to do an incremental replacing-operation automatically as many times as it may need? For example, if I do need to replace " 1." with "</br><b>1.</b>", then replace " 2." with "</br><b>2.</b>" and then replace " 3." with "</br><b>3.</b>" and so on and so forth until it increases to "#n." which "#n." doesn't exist in this file and I could not do the replace action any more. How to let UE do this kind of replacement automatically? Since manually making this replacment is tiresome.

    And similarly, is it possible to let UE smartly in alphabetical order replace letter " a)" with "</br><b> a)</b>", then replace "b)" with "</br><b> b)</b>", and then replace letter "c)"with "</br><b> c)</b>" and so on and so forth, until it reaches to letter "n)" which "n)" doesn't exist and quit the replacement?

    6,675585
    Grand MasterGrand Master
    6,675585

      Jan 13, 2009#2

      The following macro written for UE v14.20.1.1006 should do what you want. It first replaces all numbers inside (...) by special strings.

      Attention: That works only for (...) on the same line. Something like ( at line X with the corresponding ) at line Y is not supported. Also ( without corresponding ) will be handled nevertheless as (...).

      Then it inserts the HTML elements around the remaining numbers as you want it. Next it replaces the special strings back to numbers. The last regular expression string is for alphabetic list items.

      If you get an error when you close the macro edit dialog after copying the macro code into the dialog for a new macro, replace command UltraEditReOn by UnixReOff which was the previous name for that command in previous versions of UltraEdit.

      The macro property Continue if search string not found must be checked for this macro.

      InsertMode
      ColumnModeOff
      HexOff
      UltraEditReOn
      Top
      Loop 0
      Find RegExp "^(([~^r^n)0]+^)0"
      Replace All "^1#ZeRo#"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Loop 0
      Find RegExp "^(([~^r^n)1]+^)1"
      Replace All "^1#OnE#"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Loop 0
      Find RegExp "^(([~^r^n)2]+^)2"
      Replace All "^1#TwO#"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Loop 0
      Find RegExp "^(([~^r^n)3]+^)3"
      Replace All "^1#ThReE#"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Loop 0
      Find RegExp "^(([~^r^n)4]+^)4"
      Replace All "^1#FoUr#"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Loop 0
      Find RegExp "^(([~^r^n)5]+^)5"
      Replace All "^1#FiVe#"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Loop 0
      Find RegExp "^(([~^r^n)6]+^)6"
      Replace All "^1#SiX#"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Loop 0
      Find RegExp "^(([~^r^n)7]+^)7"
      Replace All "^1#SeVeN#"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Loop 0
      Find RegExp "^(([~^r^n)8]+^)8"
      Replace All "^1#EiGhT#"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Loop 0
      Find RegExp "^(([~^r^n)9]+^)9"
      Replace All "^1#NiNe#"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Find RegExp "^([0-9].^)"
      Replace All "</br><b>^1</b>"
      Find MatchCase "#ZeRo#"
      Replace All "0"
      Find MatchCase "#OnE#"
      Replace All "1"
      Find MatchCase "#TwO#"
      Replace All "2"
      Find MatchCase "#ThReE#"
      Replace All "3"
      Find MatchCase "#FoUr#"
      Replace All "4"
      Find MatchCase "#FiVe#"
      Replace All "5"
      Find MatchCase "#SiX#"
      Replace All "6"
      Find MatchCase "#SeVeN#"
      Replace All "7"
      Find MatchCase "#EiGhT#"
      Replace All "8"
      Find MatchCase "#NiNe#"
      Replace All "9"
      Find MatchCase RegExp " ^([a-z])^)"
      Replace All "</br><b>^1</b>"
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Jan 13, 2009#3

        Mofi ,you are such a genius! Thanks a lot! Very helpful indeed!