Grep Pattern, matching any two consecutive words having 3 to 8 chars each

Discussion in 'Perl Misc' started by User, Jun 13, 2004.

  1. User

    User Guest

    Hi,

    What is the grep pattern to match (in a one line phrase) at least two
    consecutive words having min 3 to max 8 chars each (number of chars need NOT be
    the same in the two words)?

    I can't find the proper pattern for that. It needs to be done solely by the
    regexp engine (no further Perl instruction other than to recuperate the words
    from the submatches).

    Anyone knows?

    Thanks a lot,

    Daniel M.
    User, Jun 13, 2004
    #1
    1. Advertising

  2. User

    Bob Walton Guest

    User wrote:

    ....


    > What is the grep pattern to match (in a one line phrase) at least two
    > consecutive words having min 3 to max 8 chars each (number of chars need NOT be
    > the same in the two words)?
    >
    > I can't find the proper pattern for that. It needs to be done solely by the
    > regexp engine (no further Perl instruction other than to recuperate the words
    > from the submatches).

    ....
    > Daniel M.
    >
    >
    >


    Maybe something like:

    /(\w{3,8})\s+(\w{3,8})/

    ?

    --
    Bob Walton
    Email: http://bwalton.com/cgi-bin/emailbob.pl
    Bob Walton, Jun 13, 2004
    #2
    1. Advertising

  3. User

    User Guest

    > Maybe something like:
    >
    > /(\w{3,8})\s+(\w{3,8})/


    Thanks Bob.


    I oversimplified my problem. My bad :-(

    What if I want a match when from 2 to 6 consec words having min 3 to 8 chars?

    Regards,

    Daniel M.
    User, Jun 13, 2004
    #3
  4. User

    Ben Morrow Guest

    Quoth "User" <>:
    > > Maybe something like:
    > >
    > > /(\w{3,8})\s+(\w{3,8})/

    >
    > Thanks Bob.
    >
    > I oversimplified my problem. My bad :-(
    >
    > What if I want a match when from 2 to 6 consec words having min 3 to 8
    > chars?


    This, particularly the 'must be a single regex' bit, smells of homework.
    Nevertheless, try

    /\w{3,8} (?: \s+ \w{3,8} ){1,5}/x

    Now go read perldoc perlretut.

    Ben

    --
    I've seen things you people wouldn't believe: attack ships on fire off
    the shoulder of Orion; I watched C-beams glitter in the dark near the
    Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
    Time to die.
    Ben Morrow, Jun 13, 2004
    #4
  5. User

    User Guest

    Ben,

    Thanks very much. :)

    > >
    > > What if I want a match when from 2 to 6 consec words having min 3 to 8
    > > chars?

    >
    > This, particularly the 'must be a single regex' bit, smells of homework.


    Nope. No homework (but not work either).
    Just something I wanted to know how to do.

    > Nevertheless, try
    > /\w{3,8} (?: \s+ \w{3,8} ){1,5}/x


    I _knew_ I'd get some great help here.

    > Now go read perldoc perlretut.


    Thanks for the tip.

    Regards,

    Daniel M.
    User, Jun 13, 2004
    #5
  6. Bob Walton <> wrote:
    > User wrote:
    >
    > ...
    >
    >
    >> What is the grep pattern to match (in a one line phrase) at least two
    >> consecutive words having min 3 to max 8 chars each (number of chars need NOT be
    >> the same in the two words)?
    >>
    >> I can't find the proper pattern for that. It needs to be done solely by the
    >> regexp engine (no further Perl instruction other than to recuperate the words
    >> from the submatches).

    > ...
    >> Daniel M.
    >>
    >>
    >>

    >
    > Maybe something like:
    >
    > /(\w{3,8})\s+(\w{3,8})/

    ^^
    ^^

    That should likely be \W instead...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jun 13, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. danpres2k
    Replies:
    3
    Views:
    7,469
    danpres2k
    Aug 25, 2003
  2. CV
    Replies:
    2
    Views:
    589
    Charles DeRykus
    Aug 31, 2004
  3. CV
    Replies:
    4
    Views:
    133
    Gunnar Hjalmarsson
    Aug 31, 2004
  4. viki
    Replies:
    14
    Views:
    245
    Ben Bullock
    Jun 20, 2008
  5. Replies:
    1
    Views:
    127
    A. Sinan Unur
    Mar 12, 2009
Loading...

Share This Page