[英]Regular Expression Java - check invoice number
I need to build a regular expression for checking the invoice number like this: FV/1024/02/2018
我需要构建一个正则表达式来检查发票号码,如下所示:
FV/1024/02/2018
FV
- using always FV nothing different FV
- 始终使用 FV 没什么不同1024
- next numer of invoice - alway starting with "1" next three numbers are different [0-9]
1024
- 发票的下一个数字 - 总是以“1”开头,接下来的三个数字不同[0-9]
02
- month - always on number 1-12 02
- 月 - 总是在 1-12 号2018
- a year 2018
- 一年i have:我有:
Pattern pattern = Pattern.compile("([FV])/((1)[0-9]{3})/([0,1]{1}[0-9]{1})/([0-9]{4})");
and i know..."something" wrong ...我知道……“有事”错了……
This should work这应该工作
FV\/1\d{3}\/(:?(:?0[1-9])|1[0-2])\/\d{4}
FV\\/
matches first, constant part ( FV/
) string FV\\/
首先匹配常量部分 ( FV/
) 字符串1\\d{3}\\/
is an invoice number - starting with 1 and followed by 3 digits 1\\d{3}\\/
是发票编号 - 以 1 开头,后跟 3 位数字(:?(:?0[1-9])|1[0-2])
is a month number (:?(:?0[1-9])|1[0-2])
是月份数
(:?0[1-9])
from 01
to 09
OR (:?0[1-9])
从01
到09
或1[1-2]
from 10
to 12
1[1-2]
从10
到12
\\/\\d{4}
is slash year, eg /2018
\\/\\d{4}
是斜线年份,例如/2018
This should work (it matches your given invoice number: 'FV/1024/02/2018'):这应该有效(它与您给定的发票编号匹配:“FV/1024/02/2018”):
FV\/(1[0-9]{3})\/([0-9]{2})\/([0-9]{4})
The Invoice Number, Month an Year each have their own Group.发票编号,每年每月都有自己的组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.