开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜