-
October 26th, 2010, 02:10 PM
#1
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
-
October 27th, 2010, 04:01 AM
#2
Re: Regular Expression
Originally Posted by gulumal
"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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|