Regualr Expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • willl69

    Regualr Expression

    Hi,

    Just wondering if anybody can help me out with a regular expression.

    What i need to do is match a sting of 5+ words, with the words in any
    order. The below will perform the operation -

    ^(word1|word2|w ord3|word4|word 5)+$

    Although this works, this will also match alot of stuff that contains any
    of those words, not contains all the words, which is what i need.

    Any info greatly appreciated, i can ellaborate on the problem if needed,

    Cheers

    Will

  • lister

    #2
    Re: Regualr Expression

    On Feb 23, 11:59 am, "willl69" <will...@gmail. comwrote:
    Hi,
    >
    Just wondering if anybody can help me out with a regular expression.
    >
    What i need to do is match a sting of 5+ words, with the words in any
    order. The below will perform the operation -
    >
    ^(word1|word2|w ord3|word4|word 5)+$
    >
    Although this works, this will also match alot of stuff that contains any
    of those words, not contains all the words, which is what i need.
    >
    Any info greatly appreciated, i can ellaborate on the problem if needed,
    >
    Cheers
    >
    Will
    ^(word1|word2|w ord3|word4|word 5){5}$

    Will require 5 words, but this will still let your user enter the same
    word 5 times. Do you need an instance of all 5 words?

    Comment

    • Janwillem Borleffs

      #3
      Re: Regualr Expression

      willl69 schreef:
      Just wondering if anybody can help me out with a regular expression.
      >
      What i need to do is match a sting of 5+ words, with the words in any
      order. The below will perform the operation -
      >
      ^(word1|word2|w ord3|word4|word 5)+$
      >
      Although this works, this will also match alot of stuff that contains any
      of those words, not contains all the words, which is what i need.
      >
      Any info greatly appreciated, i can ellaborate on the problem if needed,
      >
      The following will report invalid words, but won't check that all words
      are present:

      $sentence = 'word1word2';

      if (count(preg_spl it('/(word1|word2|wo rd3|word4|word5 )/',
      $sentence,
      -1,
      PREG_SPLIT_NO_E MPTY))) {
      print 'unknown words found';
      }


      JW

      Comment

      • willl69

        #4
        Re: Regular Expression

        That would work, however i need it in the one regular expression if
        possible as it needs to port across platforms (ie php, mysql, perl). Its
        highly possible that it is completely impossible, just trying to save my
        self extra coding

        Comment

        • Rik

          #5
          Re: Regular Expression

          On Fri, 23 Feb 2007 13:48:35 +0100, willl69 <willl69@gmail. comwrote:
          That would work, however i need it in the one regular expression if
          possible as it needs to port across platforms (ie php, mysql, perl). Its
          highly possible that it is completely impossible, just trying to save my
          self extra coding
          >
          The only way I see it done in a regular expressions is a hidous nested
          beast of a regex, which details all of the possibilities. Regex is
          certainly no way to go here.
          --
          Rik Wasmus

          Comment

          Working...