Regex match first characters of string
I am trying to create a regex that will match the first 3 characters of a string,
If I have a string ABCFFFF I want to verify that th开发者_如何学Goe first 3 characters are ABC.
It's pretty straightforward, the pattern would be ^ABC
As others may point out, using regular expressions for such a task is an overkill. Any programming language with regex support can do it better with simple string manipulations.
Just simple regex will work:
/^ABC/
But is it a good use case for using regex, I am not sure. Consider using substring
in whatever language/platform you're using.
"^ABC" should work. '^' matches the start in most regex implementations.
精彩评论