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
精彩评论