/^[a]*$/ reads as
1) Match the start of the string,
2) immediately followed by 0 or more 'a',
3) immediately followed by "\n" (optional) and the end of the string.
When matching against "1", step (3) fails.
1) Match the start of the string -> ok, pos = 0
2) immediately followed by 0 or more 'a' -> ok (matched 0 'a's), pos = 0
3) immediately followed by "\n" (optional) and the end of the string -> fail (no "\n" or eos at pos 0)
/^[a]*/ reads as:
1) Match the start of the string,
2) immediately followed by 0 or more 'a'.
When matching against "1", it matches.
1) Match the start of the string -> ok, pos = 0
2) immediately followed by 0 or more 'a' -> ok (matched 0 'a's), pos = 0
U: Changed "followed" to "immediately followed" for extra clarity.
U: Added '"\n" (optional) and'.
In reply to Re: Regex Semantics
by ikegami
in thread Regex Semantics
by cbro
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |