开发者

Regular expression matching specific letter combos

I need to match the following example strings:

LA20517505 BN30116471

I tried this: [LA|BN].\d{8}

That does indeed match, but it also matches other letters as well. I spec开发者_StackOverflowifically need to match "LA" or "BN" followed by 8 numbers.


Don't use brackets here but parenthesis : (LA|BN)\d{8}

Explanation:

(LA|BN) Match character sequences LA or BN
\d{8}   followed by 8 digits

whereas the initial regex [LA|BN].\d{8} can be read as :

[LA|BN]  Match either character L,A,|,B or N 
.        Match any character
\d{8}   followed by 8 digits
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜