A regex does not have to match an entire string. The regex instead will attempt to match any substring of a string. For instance, [a-c]+[def]+ will match abcdef or aaaaad or acfff, but it would also match 012abcdef345 because [a-c]+[def]+ is found somewhere within the string. In fact, the regex [0-9]* would match anything since the * means "0 or digits" and any string, even the empty string, will have at least 0 digits! In order to "control" where the regex matches, we add ^ to indicate "match at the start of the string" and $ to indicate "match at the end of the string". Here are several examples.


NOTE: to replay, right click and select Play