Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialkaran Badhwar
Web Development Techdegree Graduate 18,135 Pointshelp understanding it
I did not get it how this worked *, + {}, can somebody please elaborate this to me with example? How * and + matches and what it matches Please
3 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsGiven an preceding element such as a character “a”, a character list “[a-z]” or a group “(bar)”, the characters mean:
-
+
one or more of the preceding element -
*
zero or more of the preceding element -
{}
is a range of repeating the preceding element
Post back if you need more help. Good luck!!!
karan Badhwar
Web Development Techdegree Graduate 18,135 PointsSo you mean to say untill the word is not completed it will keep on adding the words to make a single string?
Chris Freeman
Treehouse Moderator 68,441 PointsThe regular expression (regex) is used as a “recipe template” to compare to a string. A string is “consumed” one character at a time and checked against the regex to see if the regex pattern still holds true. If the string is exhausted before the regex end or if the regex end is reached before the sting is fully consumed, then the is no matching result.
So given the regex toy\w+
and the “toycar”:
t o y \w+
| | | |
o o o x
k k k x fail
| | | |
t o y
this fails because at lease on more character was expected after the “y”
In the case of the \w*
no extra charters are expected after the “y” so the regex will match the string.
karan Badhwar
Web Development Techdegree Graduate 18,135 PointsThankyou Chris, I really appreciate the help and happy holidays and merry Christmas to you and your family
karan Badhwar
Web Development Techdegree Graduate 18,135 Pointskaran Badhwar
Web Development Techdegree Graduate 18,135 PointsSir I did not get it now after these videos am exhausted and confused completely?
I am unable to understand how it is comparing
ex- toy\w* vs toy\w+
over here what is being compared (\w) only or the full set and how the further stuff gets matched
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 Pointstoy\w*
means “toy” followed by zero or more word characters.So this would match
“toycar” (more than one following character)
toy\w+
means “toy” followed by one or more word characters.So this would match
It would not match