Loading ...
Sorry, an error occurred while loading the content.

Find and Replace RegEx

Expand Messages
  • patriciat.geo
    In a directory list of files, I would like to remove all the material after the file names. 1800nycen.htm View Apr 14th, 2004 1979 1881reun.htm View Apr 14th,
    Message 1 of 6 , Apr 17, 2004
    • 0 Attachment
      In a directory list of files, I would like to remove all the material
      after the file names.

      1800nycen.htm View Apr 14th, 2004 1979
      1881reun.htm View Apr 14th, 2004 4577
      2001.htm View Apr 14th, 2004 1776
      Bnumber.htm View Apr 14th, 2004 7881

      Is it possible to specify the removal of everything
      after .htm ? in Find/Replace?

      Thanks

      Patricia
    • John Zeman
      ... material ... Assuming you literally mean that all files end in .htm you can do it with a regular expression clip like this Patricia. ^!Replace
      Message 2 of 6 , Apr 18, 2004
      • 0 Attachment
        --- In ntb-clips@yahoogroups.com, "patriciat.geo" <patricia@e...>
        wrote:
        > In a directory list of files, I would like to remove all the
        material
        > after the file names.
        >
        > 1800nycen.htm View Apr 14th, 2004 1979
        > 1881reun.htm View Apr 14th, 2004 4577
        > 2001.htm View Apr 14th, 2004 1776
        > Bnumber.htm View Apr 14th, 2004 7881
        >
        > Is it possible to specify the removal of everything
        > after .htm ? in Find/Replace?
        >
        > Thanks
        >
        > Patricia

        Assuming you literally mean that all files end in .htm you can do it
        with a regular expression clip like this Patricia.

        ^!Replace "{^.*\.htm\s}" >> "^%EMPTY%" WRA

        The curly braces { } are optional but I like to use them in case I
        want to use what's in between the curly braces in the replace
        operation. That is, if the clip was like this instead:

        ^!Replace "{^.*\.htm\s}" >> "Hello\s\1There\s" WRA

        It would surround the file names with "Hello" and "There"

        Now to describe how the first regexp clip works (because I know you
        are trying to learn regexp)

        The ^ means starting at the beginning of each line

        The ^.* means there can be anything starting at the beginning of each
        line.

        The ^.*\. means anything starting at the beginning of each line that
        ends in a period. The period must be escaped with the \ because
        normally a period has special meaning.

        The ^.*\.htm means starting at the beginning of each line find
        anything as long as it ends in .htm

        The ^.*\.htm\s means the same as the previous line but requires a
        space after the .htm

        So the first clip finds anything at the beginning of each line in the
        document that ends in .htm followed by a space and then replaces that
        with the value of the NoteTab variable ^%EMPTY% which is a null
        value, or nothing.

        John
      • John Zeman
        OOPS! It must be too early on a Sunday morning for me, that last clip I posted does the exact opposite of what you asked for. Give me a few minutes to
        Message 3 of 6 , Apr 18, 2004
        • 0 Attachment
          OOPS! It must be too early on a Sunday morning for me, that last
          clip I posted does the exact opposite of what you asked for. Give me
          a few minutes to rewrite it.

          John
        • Don - htmlfixit.com
          ... I was wondering about you! won t just using 1 for the replace do it? instead of ^%EMPTY%
          Message 4 of 6 , Apr 18, 2004
          • 0 Attachment
            John Zeman wrote:

            > --- In ntb-clips@yahoogroups.com, "patriciat.geo" <patricia@e...>
            > wrote:
            >
            >>In a directory list of files, I would like to remove all the
            >
            > material
            >
            >>after the file names.
            >>
            >>1800nycen.htm View Apr 14th, 2004 1979
            >> 1881reun.htm View Apr 14th, 2004 4577
            >> 2001.htm View Apr 14th, 2004 1776
            >> Bnumber.htm View Apr 14th, 2004 7881
            >>
            >>Is it possible to specify the removal of everything
            >>after .htm ? in Find/Replace?
            >>
            >>Thanks
            >>
            >>Patricia
            >
            >
            > Assuming you literally mean that all files end in .htm you can do it
            > with a regular expression clip like this Patricia.
            >
            > ^!Replace "{^.*\.htm\s}" >> "^%EMPTY%" WRA
            >
            > The curly braces { } are optional but I like to use them in case I
            > want to use what's in between the curly braces in the replace
            > operation. That is, if the clip was like this instead:
            >
            > ^!Replace "{^.*\.htm\s}" >> "Hello\s\1There\s" WRA
            >
            > It would surround the file names with "Hello" and "There"
            >
            > Now to describe how the first regexp clip works (because I know you
            > are trying to learn regexp)
            >
            > The ^ means starting at the beginning of each line
            >
            > The ^.* means there can be anything starting at the beginning of each
            > line.
            >
            > The ^.*\. means anything starting at the beginning of each line that
            > ends in a period. The period must be escaped with the \ because
            > normally a period has special meaning.
            >
            > The ^.*\.htm means starting at the beginning of each line find
            > anything as long as it ends in .htm
            >
            > The ^.*\.htm\s means the same as the previous line but requires a
            > space after the .htm
            >
            > So the first clip finds anything at the beginning of each line in the
            > document that ends in .htm followed by a space and then replaces that
            > with the value of the NoteTab variable ^%EMPTY% which is a null
            > value, or nothing.

            I was wondering about you!
            won't just using \1 for the replace do it?
            instead of "^%EMPTY%"
          • John Zeman
            ... material ... Take Two. Here you go Patricia, this one should do it. This one finds the file names exactly as I described before, but the the .* in this
            Message 5 of 6 , Apr 18, 2004
            • 0 Attachment
              --- In ntb-clips@yahoogroups.com, "patriciat.geo" <patricia@e...>
              wrote:
              > In a directory list of files, I would like to remove all the
              material
              > after the file names.
              >
              > 1800nycen.htm View Apr 14th, 2004 1979
              > 1881reun.htm View Apr 14th, 2004 4577
              > 2001.htm View Apr 14th, 2004 1776
              > Bnumber.htm View Apr 14th, 2004 7881
              >
              > Is it possible to specify the removal of everything
              > after .htm ? in Find/Replace?
              >
              > Thanks
              >
              > Patricia


              Take Two.

              Here you go Patricia, this one should do it. This one finds the file
              names exactly as I described before, but the the .* in this clip
              after the closing } refers to anything else on the line after the
              file name.

              ^!Replace "{^.*\.htm}.*" >> "\1^%EMPTY%" WRA

              In effect the entire line of each qualifying line, is replaced with
              just the file name.

              Sorry for the confusion last time, I gotta go find me some more
              coffee.

              John
            • John Zeman
              ... You re right Don, the ^%EMPTY% I used in the second part isn t really necessary, the clip should work fine without it. Since I had used it in my first
              Message 6 of 6 , Apr 18, 2004
              • 0 Attachment
                --- In ntb-clips@yahoogroups.com, "Don - htmlfixit.com" <don@h...>
                wrote:
                > I was wondering about you!
                > won't just using \1 for the replace do it?
                > instead of "^%EMPTY%"


                You're right Don, the ^%EMPTY% I used in the second part isn't really
                necessary, the clip should work fine without it. Since I had used it
                in my first clip that did the opposite of what Patricia wanted (duh),
                I just left it in there when I rewrote the clip.

                FWIW mostly from using other programming languages I have a habit of
                using a null value variable instead of just nothing. Either works in
                clips.

                By the way you're not alone, everyone wonders about me, even I wonder
                about me sometimes! LOL

                John
              Your message has been successfully submitted and would be delivered to recipients shortly.