Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regex help

Last post 08-29-2008, 10:51 PM by dipendra. 3 replies.
Sort Posts: Previous Next
  •  08-29-2008, 8:17 PM 45788

    Regex help

    Hi there

    How can i achive this

    I need to add the below rule to this regex  ^[\s-a-zA-Z]{2,40}

    Blanks and hyphens must be preceded and followed by alphabetic characters.

     

    Many thanks

    Dipendra

  •  08-29-2008, 8:45 PM 45789 in reply to 45788

    Re: Regex help

    ^(?=[\sa-zA-Z-]{2,40}$)(?!^[\s-]|.*(?:[\s-]{2}|[\s-]$)).*$


  •  08-29-2008, 10:33 PM 45795 in reply to 45788

    Re: Regex help

    dipendra:

    Blanks and hyphens must be preceded and followed by alphabetic characters.

    Here's how I understood that requirement:

    • string cannot start or end with [\s-] since there's no way for an alphabetic character to precede and follow [\s-] in that case
    • there cannot be any [\s-] followed by another [\s-] since an alphabetic character is required to follow it, since there are only [\s-] and [a-zA-Z] allowed in the string that rule should cover the requirement of [a-zA-Z] preceding [\s-].

  •  08-29-2008, 10:51 PM 45796 in reply to 45789

    Re: Regex help

    Thank you for your help.

    Dipendra

View as RSS news feed in XML