[thelist] ASP - Regular Expressions (Correction)

Frank lists at frankmarion.com
Tue Aug 5 12:01:33 CDT 2003

At 03:20 AM 2003-08-05 -0400, you wrote:
>I don't want the user to be able to input '--text' or 'text--' but able to 
>input 'te-xt'.
>At the moment this is working properly for everything but 'text--'. It 
>still allows the user to do this. I don't really know why except that it 
>relates to the $ sign, because I first read about regular expressions today.

Oop! Screw'd up! Correction

The following will accept any alpha-numeric (or dashes) that is not 
preceded or followed by one or more dashes. If there is not one or more 
matches, it will fail-- test failed.


^ line start
    [1] repeat at least 1 time
          [^-]+ One or more of any character that is not a dash
          [a-zA-Z0-9-] + One or more of upper or lower case alpha-num or dash
          [^-]+ One or more of any character that is not a dash
$ line end

The following will successfully match

And it will fail any of these
-- text (no space in specified in the second sub-expression   [a-zA-Z0-9-] +  )
-- text

To force only a single dash in the center of a word use [a-zA-Z0-9-] with no +

Because this is all grouped with parentheses, the whole expression is 
treated as one. If you were to remove the parentheses, each [subexpression] 
would be treated as a single character, thus the text would be for three 
sequential characters.

Frank Marion     lists at frankmarion.com      Keep the signal high.  

More information about the thelist mailing list