Regex howto

2007-05-30
2012-11-13
  • Hi,

    I don't understand how to use the regex search and replace. Perhaps an example will help me get the hang of it:

    I have a text file with sequences of characters like

    {\bf “The Dervish Lodge: Architecture, Art, and Sufism in Ottoman Turkey.”}

    I would like to search for

    \{\\bf “(.*?)”\}

    and replace with

    \index{\bf $1}

    where '$1' represents what's in parens

    basically I want to get rid of the quotes and index what's in brackets. How do I do this using the regex dialog?

    Best
    Idris

     
    • bdb4269
      bdb4269
      2007-05-30

      Try this

      search
      \{(\\bf) "(.*)"\}

      replace
      \index{\1 \2}

      Basically - Take the "?" out -- and use \1 instead of $1 to reference

      (I used ()'s around the \bf - because i was having trouble with the \b in the replace adding a BS instead of "\b")

       
      • Hi,

        Thank you: the following works in my case:

        search
        \{(\\bf) “(.*)”\}

        replace
        \index{\1 \2}

        The only difference being the kind of quotes used in my specific case.

        If I am understanding correctly, the '\' is an escape character in the Replace dialog and everything else is treated as text. Are there any other escape characters for the replace? (I think I understand the search side of regex's better than I get the rules for the replace side).

        THNX: I really appreciate it!
        Idris

         
        • bdb4269
          bdb4269
          2007-05-31

          I was actually curous about this myself. 

          When trying to solve this regex problem -- I tried using an extra "\&quot; in the replace to 'escape' the "\&quot; before the "b" in the replace -- (\index{\\bf \1} -- but it still translated the \b into a BS resulting in "\index(\BSf <text>)

          (Where BS = special character (backspace I think?)

          Does anyone know how you could insert a literal "\b" into a replace, without tagging "\b" from the search, and just refferencing it in the replace? Basically, if "\b" was not in the original text -- how could I insert it, in a regex search/replace?

           
    • pshute
      pshute
      2007-05-31

      • That's a great help, did not see that one before...

        THNX
        I