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

Re: Searching for words that are repeated more than once consecutively

Expand Messages
  • Bram Moolenaar
    ... / ( ) s + 1 -- Q: What do you call a fish without an eye? A: fsh! /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net ///
    Message 1 of 10 , Jul 2, 2002
    • 0 Attachment
      Yegappan Lakshmanan wrote:

      > How do I search for words that are repeated consecutively more
      > than once? For example, search for "the the" or "a a", etc.
      > Note that the word is an arbitrary word (i.e. I cannot just
      > search for /the the or /a a).

      /\(\<\k\+\>\)\s\+\1

      --
      Q: What do you call a fish without an eye?
      A: fsh!

      /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
      /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\
      \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
      \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
    • Preben Peppe Guldberg
      ... I d say that should be / ( ) s + 1 or an anchor will be matched, too. Peppe -- Before you criticize someone, walk Preben Peppe Guldberg
      Message 2 of 10 , Jul 2, 2002
      • 0 Attachment
        Thus wrote Bram Moolenaar (Bram@...) on [020702]:

        > Yegappan Lakshmanan wrote:

        > > How do I search for words that are repeated consecutively more
        > > than once? For example, search for "the the" or "a a", etc.
        > > Note that the word is an arbitrary word (i.e. I cannot just
        > > search for /the the or /a a).

        > /\(\<\k\+\>\)\s\+\1

        I'd say that should be

        /\(\<\k\+\>\)\s\+\1\>

        or "an anchor" will be matched, too.

        Peppe
        --
        "Before you criticize someone, walk
        Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
        c928400@... (o o) he gets angry, he'll be a mile away
        ----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
      • Gary Holloway
        / FROM: Preben Peppe Guldberg , Jul 2 20:51 2002 ... Actually, I d use: / ( ) ( _s + ) + After all, you wanna find the
        Message 3 of 10 , Jul 2, 2002
        • 0 Attachment
          / FROM: Preben Peppe Guldberg <c928400@...>, Jul 2 20:51 2002
          | ABOUT: Re: Searching for words that are repeated more than once consecutively
          |
          | Thus wrote Bram Moolenaar (Bram@...) on [020702]:
          |
          | > Yegappan Lakshmanan wrote:
          |
          | > > How do I search for words that are repeated consecutively more
          | > > than once? For example, search for "the the" or "a a", etc.
          | > > Note that the word is an arbitrary word (i.e. I cannot just
          | > > search for /the the or /a a).
          |
          | > /\(\<\k\+\>\)\s\+\1
          |
          | I'd say that should be
          |
          | /\(\<\k\+\>\)\s\+\1\>

          Actually, I'd use:

          /\(\<\k\+\>\)\(\_s\+\<\1\>\)\+

          After all, you wanna find "the the the", right? :)
          (and of course,
          the
          the
          the
          )

          Now, is there a way to skip a comment leader?
          To find something like:

          /* This comment repeats the
          * the word, "the" consecutively.
          */

          Which would be one of the more common cases of a repeated word you'd miss. :)

          -gary

          |
          | or "an anchor" will be matched, too.
          |
          | Peppe
          | --
          | "Before you criticize someone, walk
          | Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
          | c928400@... (o o) he gets angry, he'll be a mile away
          | ----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
          |
          \ END: Preben Peppe Guldberg
        • Gary Holloway
          / FROM: Gary Holloway , Jul 2 17:29 2002 ... Well, ok, I guess this d work: / ( ) ( ( _s + | s* n s* * s* ) ) + ... [snip]
          Message 4 of 10 , Jul 2, 2002
          • 0 Attachment
            / FROM: Gary Holloway <gary@...>, Jul 2 17:29 2002
            | ABOUT: Re: Searching for words that are repeated more than once consecutively
            |
            | / FROM: Preben Peppe Guldberg <c928400@...>, Jul 2 20:51 2002
            | | ABOUT: Re: Searching for words that are repeated more than once consecutively
            | |
            | | Thus wrote Bram Moolenaar (Bram@...) on [020702]:
            | |
            | | > Yegappan Lakshmanan wrote:
            | |
            | | > > How do I search for words that are repeated consecutively more
            | | > > than once? For example, search for "the the" or "a a", etc.
            | | > > Note that the word is an arbitrary word (i.e. I cannot just
            | | > > search for /the the or /a a).
            | |
            | | > /\(\<\k\+\>\)\s\+\1
            | |
            | | I'd say that should be
            | |
            | | /\(\<\k\+\>\)\s\+\1\>
            |
            | Actually, I'd use:
            |
            | /\(\<\k\+\>\)\(\_s\+\<\1\>\)\+
            |
            | After all, you wanna find "the the the", right? :)
            | (and of course,
            | the
            | the
            | the
            | )
            |
            | Now, is there a way to skip a comment leader?
            | To find something like:
            |
            | /* This comment repeats the
            | * the word, "the" consecutively.
            | */
            |
            | Which would be one of the more common cases of a repeated word you'd miss. :)

            Well, ok, I guess this'd work:

            /\(\<\k\+\>\)\(\(\_s\+\|\s*\n\s*\*\s*\)\<\1\>\)\+

            |
            | -gary
            |
            | |
            [snip]
            | |
            | \ END: Preben Peppe Guldberg
            |
            |
            \ END: Gary Holloway
          • Robert Montante
            ... Ummm... why are you guys all using the k atom? Wouldn t w make more sense? So here s my entry: / ( ) _s* 1 (This should match the first
            Message 5 of 10 , Jul 3, 2002
            • 0 Attachment
              >Bram Moolenaar:
              > /\(\<\k\+\>\)\s\+\1
              >
              >Preben Peppe Guldberg:
              > /\(\<\k\+\>\)\s\+\1\>
              >
              >Gary Holloway:
              > /\(\<\k\+\>\)\(\_s\+\<\1\>\)\+

              Ummm... why are you guys all using the "\k" atom? Wouldn't "\w" make
              more sense?
              So here's my entry:
              /\(\<\w\+\>\)\_s*\1\>

              (This should match the first two words of a three-word repetition.)

              -bob,mon.
            • Gary Holloway
              / FROM: Robert Montante , Jul 3 9:04 2002 ... It really depends what you consider a word that you re looking for. w Will only find
              Message 6 of 10 , Jul 3, 2002
              • 0 Attachment
                / FROM: Robert Montante <bobmon@...>, Jul 3 9:04 2002
                | ABOUT: Re: Searching for words that are repeated more than once consecutively
                |
                | >Bram Moolenaar:
                | > /\(\<\k\+\>\)\s\+\1
                | >
                | >Preben Peppe Guldberg:
                | > /\(\<\k\+\>\)\s\+\1\>
                | >
                | >Gary Holloway:
                | > /\(\<\k\+\>\)\(\_s\+\<\1\>\)\+
                |
                | Ummm... why are you guys all using the "\k" atom? Wouldn't "\w" make
                | more sense?

                It really depends what you consider a "word" that you're looking for.

                \w Will only find [0-9A-Za-z_]
                \k Is dependent upon your 'iskeyword' setting.

                It's really a matter of preference.

                -gary

                | So here's my entry:
                | /\(\<\w\+\>\)\_s*\1\>
                |
                | (This should match the first two words of a three-word repetition.)
                |
                | -bob,mon.
                |
                \ END: Robert Montante
              Your message has been successfully submitted and would be delivered to recipients shortly.