Find All Text Between String A and String B, Exclusive

Find All Text Between String A and String B, Exclusive

howardg22

    May 18, 2005#1

    I'm sure there is a simple solution, but I cannot find it (new to RegExp). Does anyone know how to do this?

    I'm trying to use a RegExp to find text between 2 strings that excludes those 2 strings. Below, I want "this" (sandwiched between [ and , ).

    Line[this,that]

    UE RegExp's that I've tried are:
    ^[+*,+
    ^[+^(*^),+

    261
    Basic UserBasic User
    261

      May 19, 2005#2

      chadrey,

      You threw me off in the description ("between 2 strings"), but I think the example using characters can be done.

      Just search for the following:
      (I use Unix style RE)

      \[[^\[,]*,

      This says search for the literal "[" character, followed by any number of characters that are not a left bracket or comma, followed by a comma.

      I'm sure you can do the same thing with UE REs if you want.

      If you really wanted to search for something "between 2 strings that excludes those 2 strings", I don't know how to do that.

      Dave
      ASTTMan
      I'm not a Texan, I just live here.

      howardg22
      howardg22

        May 19, 2005#3

        Dave,

        Thanks for that regexp. It works except that it selects the opening/closing characters in the match (Line[MyContent,,that] but I want Line[MyContent,that]). That is what I meant by exclusive, don't select the opening/closing characters in the match.

        I've figured out the end match (ue style) [~,]+ but I'm having trouble figuring out how to match the beginning [ without actually selecting it.

        Thanks for the assistance.

        261
        Basic UserBasic User
        261

          May 19, 2005#4

          chadrey,

          Oh, I see what you mean. I'm afraid I don't know any way to do exactly what you ask. Now, what you want to do with this find may affect how you proceed. For example, if you want to do a replace, or even extract the found items, you could do it with one more step.

          If you wanted to replace the string, you could put parens around the desired section, such as: "\[([^\[,]*),". In the replace string you could refer to the contents as "\1", which would be the string between the delimiters.

          If you want to extract the contents into a list, you can check "List Lines Containing String" in the find dialog and paste them into a file. It would then be a simple step to get rid of the delimiters. (Replace "\[([^\[,]*)," with "\1")

          I'm not sure how else to approach it. Maybe if you could give some more detail on what you want to do once you have found the string, I'd have some other ideas.

          Dave
          ASTTMan
          I'm not a Texan, I just live here.

          howardg22
          howardg22

            May 20, 2005#5

            Maybe a single RegExp cannot do this? All of the documentation mentions "Match" and I'm looking for a "Find position, then start matching".

            I put it in a macro.

            InsertMode
            ColumnModeOff
            HexOff
            UnixReOff
            ClearClipboard
            Key Ctrl+HOME
            Find "["
            Key RIGHT ARROW
            SelectWord
            IfSel
            Copy
            EndIf

            Thanks for the help.