2013-01-25 50 views
1

我有正規表達式模式是這樣的:正則表達式用空格

1207181 FINAL 12 13 12 1533 

開頭:

^[a-zA-Z0-9]+\s(INV|FINAL)\s([0,1]?\d{1}\s(([0-2]?\d{1})|([3][0,1]{1}))\s(([1]{1}[9]{1}[9]{1}\d{1})|([2-9]{1}\d{3})))(\s{1})\d+$ 

如果文件名是否正確 文件名這應該符合這個模式這種模式應該驗證 - 只是數字,就像身份證。

下一個空格。

下一個INV或FINAL單詞。

格式爲dd mm yy的下一個日期。

接下來一些數字。

有人可以幫我解決這個問題嗎?

+1

什麼不行? – Bergi

+0

正則表達式有多種變體,您正在使用哪種應用程序或語言? –

+0

什麼問題? –

回答

0

您正在搜索:

^(\d+)\s(INV|FINAL)\s(0[1-9]|[12]\d|3[01])\s(0[1-9]|1[0-2])\s(\d{2})\s(\d+)$ 

說明:

^      start at the beginning of the string 
(\d+)     capture any digit 
\s      one whitespace 
(INV|FINAL)   captrue INV or FINAL 
0[1-9]     a 0 and a digit from 1 to 9 
[12]\d     a 1 or a 2 and a digit 
3[01]     a 3 and a 0 or a 1 
(0[1-9]|[1-2]\d|3[01]) capture a digit from 01 to 31 
(0[1-9]|1[0-2])  capture a 0 and a digit from 1 to 9 or a 1 and a digit from 0 to 2 | so capture a digit from 01 to 12 
(\d{2})    capture two digits 
$      stop at the end of the string 

它不會因爲13匹配1207181 FINAL 12 13 12 1533