开发者

Regex match first characters of string

开发者 https://www.devze.com 2023-03-10 01:28 出处:网络
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 straight

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消