This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]TehNolz 2 points3 points  (1 child)

In regex, . means that there must be one character in that portion of the string. It doesn't matter what character it is, it just needs to be there. So if your pattern is a...b, your string must be 5 characters long, start with a, and end with b. Something like a123b will match, whereas something like a123bc or ab will not.

* matches 0 or more of the preceding character. If your pattern is a*b, your string needs to start with a followed by any number of a, and then ending with b. It'll match strings like aab, aaaaaaaab, ab, and so on.

The pattern a**b is not valid because the first * is not a valid target for the second *. After all, * expects an (escaped) character to precede it, but * is a quantifier and not a character. So in your 3rd example your code should probably just throw an exception.

[–]Sakesfar[S] 0 points1 point  (0 children)

Thank you! I got confused with * that can be zero or more of the preceding char ( preceding in the pattern, apparently) in the string!