当前位置: 动力学知识库 > 问答 > 编程问答 >

regex - Regular expression for indian train seat numbers

问题描述:

I am trying to figure out appropriate regex for indian train seat numbers. For e.g. S10 43, B4 24 etc. I know different trains have different number of seats and coaches but a general regex will work for me. I was trying something like this:

[A|B|C|S][1-15][1-72]$

But this is not working. I also didn't find link to all types of seats in train. Can anyone help me with this?

网友答案:
[ABCS](?:1[0-5]|[1-9])\s+(?:[1-9]|[1-6][0-9]|7[0-2])$

Limiting to a given number range (1-15 and 1-72) makes it a little more complicated (as above) - it will be a lot simpler if you just accept 1- or 2-digit numbers:

[ABCS]\d\d?\s+\d\d?$

But that will match A99 99 which apparently isn't valid

分享给朋友:
您可能感兴趣的文章:
随机阅读: