This is the scenario:
All right, today i'm going to find out how to match a pattern within entire string with regex. What i mean is when i try to check a string, they must have exactly 1 numeric character in the beginning, and unlimited alpha character after. This is what i mean:
- 0432 should return false
- 0yep should return true
- dada 0yep should return false
- 0yep should return false
- 0yep should return false
so i use this regex:
preg_match('/[0-9][a-z]+/i');
Unfortunately, it also match the third, fourth, and five. After some research, i found there's ^ pattern that means "this pattern should beginning with..". So i changed it to
preg_match('/^[0-9][a-z]+/i');
and it doesn't match the third test case and the fifth case. Unfortunately, it still match the fourth. Again, after some research i found there's $ pattern that means "this pattern should end with..". So i change it to:
preg_match('/^[0-9][a-z]$+/i');
and everything work as expected.

















