Regex matches the first characters of a string

I'm trying to create a regex that matches the first 3 characters of a string,

If I have the string ABCFFFF, I want to check that the first 3 characters are ABC.

+7
source share
3 answers

It's pretty simple, the template will be ^ABC

As others point out, using regular expressions for such a task is redundant. Any regular expression programming language can do this better with simple string manipulation.

+11
source

A simple regex will work:

 /^ABC/ 

But this is a good use case for regex, I'm not sure. Consider using substring in any language / platform that you are using.

+7
source

"^ ABC" should work. '^' matches the beginning in most regular expression implementations.

0
source

All Articles