Regular Expression
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Regular Expression

  1. #1
    Join Date
    Aug 2000
    Posts
    48

    Regular Expression

    I have a regular expression.

    "^.?$"

    According to documentation "." is any character except \n
    ? is zero or one times preceding character.

    string "a" matches.
    "aa" does not match. Should "aa" match?
    "ab" does not match. Should it match?

    Can an guru explain me this please?


    thx
    gulumal

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Regular Expression

    Quote Originally Posted by gulumal View Post
    "aa" does not match. Should "aa" match?
    "ab" does not match. Should it match?
    No, it shouldn't because of ^ and $ in regular expressionm, which means begin and end of line including and the expression is evaluated as a whole. Your expression means begin-zero or just one chars-ends, but in these samples, the pattern is begin-first char-second char-end, which doesn't match, because the end of line is expected after max one char, not two.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center