Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to create an optimized regular expression?

    In another thread, someone had asked for a script to validate an input against the list of 140 standard named colors. Initially, I just stuck the whole pipe-delimited list into a regular expression
    Code:
    /^(...|...|...|...|...|...|...)$/
    and declared it done. But that seemed rather bulky, to say the least. As an alternative, I alphabetized the list, then used parenthesized subexpressions for common prefixes to make the whole regular expression more compact
    Code:
    /^(dark(...|...|...)|light(...|...|...)|...|...)$/
    . Later, I recognized that many colors rhyme, so I produced an even tighter regular expression by grouping colors with the same ending
    Code:
    /^(...|(...|...|...)blue|(...|...|...)green|...|...)$/
    . I expect that there are even tighter expressions possible with a combination of rhyming and alliterative techniques.

    I welcome your function that accepts an array of words and returns the tightest possible regular expression. Do you have one or know where I can get it?

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    removed as lack of feedback indicated that supplied script was not what the O/P was looking for and is therefore clearly redundant...
    Last edited by Willy Duitt; 11-09-2004 at 08:11 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •