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

regexp; 3 words in any order

Expand Messages
  • Yakov Lerner
    Which regular expression would match 3 words (w1,w2,w3) in any order with anything between them withinh 1 paragragh ? For example: ... w2 ..... w3 .... w1 ....
    Message 1 of 5 , Apr 3, 2006
    • 0 Attachment
      Which regular expression would match 3 words (w1,w2,w3)
      in any order with anything between them withinh 1 paragragh ?
      For example:

      ... w2 ..... w3 .... w1 .... -- paragraph matches.

      ... w3 ...w3 ..... w2.. w1.... w1 ... w2 .... -- paragraph matches.

      ... w1 ... w3 ... - paragraph does not match

      Thanks
      Yakov
    • Gerald Lai
      ... Would this do it? /.*w1 &.*w2 &.*w3 -- Gerald
      Message 2 of 5 , Apr 3, 2006
      • 0 Attachment
        On Mon, 3 Apr 2006, Yakov Lerner wrote:

        > Which regular expression would match 3 words (w1,w2,w3)
        > in any order with anything between them withinh 1 paragragh ?
        > For example:
        >
        > ... w2 ..... w3 .... w1 .... -- paragraph matches.
        >
        > ... w3 ...w3 ..... w2.. w1.... w1 ... w2 .... -- paragraph matches.
        >
        > ... w1 ... w3 ... - paragraph does not match

        Would this do it?

        /.*w1\&.*w2\&.*w3

        --
        Gerald
      • Yakov Lerner
        ... No. I need match withn paragraph not within 1 line. Thus it has to include n or _ or _ somewhere instead of .*, but exclude n n. I m not not sure how
        Message 3 of 5 , Apr 3, 2006
        • 0 Attachment
          On 4/3/06, Gerald Lai <laige@...> wrote:
          > On Mon, 3 Apr 2006, Yakov Lerner wrote:
          >
          > > Which regular expression would match 3 words (w1,w2,w3)
          > > in any order with anything between them withinh 1 paragragh ?
          > > For example:
          > >
          > > ... w2 ..... w3 .... w1 .... -- paragraph matches.
          > >
          > > ... w3 ...w3 ..... w2.. w1.... w1 ... w2 .... -- paragraph matches.
          > >
          > > ... w1 ... w3 ... - paragraph does not match
          >
          > Would this do it?
          >
          > /.*w1\&.*w2\&.*w3

          No. I need match withn paragraph not within 1 line. Thus it has to
          include \n or \_ or \_ somewhere instead of .*, but exclude \n\n. I'm not
          not sure how to express it concisely.

          Yakov
        • Mathias Michaelis
          Hi Yakov ... This regular expression matches paragraphs which contain (w1, w2, w3) in any order:
          Message 4 of 5 , Apr 3, 2006
          • 0 Attachment
            Hi Yakov

            >>> Which regular expression would match 3 words (w1,w2,w3)
            >>> in any order with anything between them within 1 paragraph?
            >>>
            This regular expression matches paragraphs which contain (w1, w2,
            w3) in any order:

            ^\s*\n\%(\%(.\|\n\s*\S\)*\<w1\>\&\%(.\|\n\s*\S\)*\<w2\>\&\%(.\|\n\s*\S\)*\<w3\>\)\_.\{-}\n\s*$

            Greetings

            Mathias
          • Gerald Lai
            ... You re welcome :) For what it s worth, here s what I came up with. I ll break the regex up, but you ll have to join it up without spaces. /^ s* %(
            Message 5 of 5 , Apr 3, 2006
            • 0 Attachment
              On Mon, 3 Apr 2006, Yakov Lerner wrote:

              > On 4/3/06, Yakov Lerner <iler.ml@...> wrote:
              >> On 4/3/06, Gerald Lai <laige@...> wrote:
              >>> On Mon, 3 Apr 2006, Yakov Lerner wrote:
              >>>
              >>>> Which regular expression would match 3 words (w1,w2,w3)
              >>>> in any order with anything between them withinh 1 paragragh ?
              >>>> For example:
              >>>>
              >>>> ... w2 ..... w3 .... w1 .... -- paragraph matches.
              >>>>
              >>>> ... w3 ...w3 ..... w2.. w1.... w1 ... w2 .... -- paragraph matches.
              >>>>
              >>>> ... w1 ... w3 ... - paragraph does not match
              >>>
              >>> Would this do it?
              >>>
              >>> /.*w1\&.*w2\&.*w3
              >>
              >> No. I need match withn paragraph not within 1 line. Thus it has to
              >> include \n or \_ or \_ somewhere instead of .*, but exclude \n\n. I'm not
              >> not sure how to express it concisely.
              >
              > I think I got it. It's
              >
              > /\(.\|.\n\)*w1\&\(.\|.\n\)*w2\&\(.\|.\n\)*w3
              >
              > Thanks Gerald
              > Yakov
              >

              You're welcome :)

              For what it's worth, here's what I came up with. I'll break the regex
              up, but you'll have to join it up without spaces.

              /^\s*\%(
              \%(\n\%(\s*\_$\)\@!.*\)\{-}w1
              \&\%(\n\%(\s*\_$\)\@!.*\)\{-}w2
              \&\%(\n\%(\s*\_$\)\@!.*\)\{-}w3\)
              \_.\{-}\ze\_^\s*$

              The search regex above follows the definition that a paragraph begins
              and ends with blank lines ^\s*$.

              You can massage the regex with \zs to make it not begin on the blank
              line, but it's going to make it longer.

              Hope this helps.
              --
              Gerald
            Your message has been successfully submitted and would be delivered to recipients shortly.