Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple regex

 
ahmed yehia
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I have the below code runs fine but I dont get the output.


output:
0332

why would it print "2" at the end after group.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you are using "*", which means zero or more times. So after finding "33", it also finds a non matching empty string, at index 2.
It would work as expected if you'd use "+" instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic