2010-11-19 3 views

ответ

1

Вы имеете в виду только что-то подобное?

/filename\.[12][90][0-9][0-9][01][0-9][0-3][0-9]/ 

Обратите внимание, что это также относится к недействительным датам.

или, более обобщенно:

/[a-zA-Z0-9_]+\.[12][90][0-9][0-9][01][0-9][0-3][0-9]/ 

вместо [a-zA-Z0-9_] вы можете использовать любые символы, ваше имя файла может содержать.

1

Попробуйте это, если вы не хотите делать какие-либо проверки.

\.(\d{8}) 
0

Простейшее:

find -regex ".*/.*\.[0-9]+$" 

Лучше:

find -regextype posix-basic -regex ".*/.*\.[0-9]\{8\}$" 

Лучший ?:

find -regextype posix-extended -regex ".*/.*\.[0-9]{4}([0][1-9]|1[012])(0[1-9]|[12][0-9]|3[01])$" 

Последняя будет найти любой год (мы не хотим повторение Y2K, сейчас, мы?). и только месяцы в диапазоне 01-12 и дни в диапазоне 01-31. Конечно, он не проверяет правильное количество дней в месяц или на високосные дни.

1

Примечание: Я предположил, что ваше «имя файла» будет только буквенно-цифровым (ASCII).


Мой лучший друг RegexBuddy говорит:

[a-zA-Z0-9]+?\.(19|20)[0-9]{2}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01]) 

Матчи

filename123.20101118 
FOOBAR123.19961212 

Не соответствует

FOOBAR.88881201 
foobar.20103512 
filename.201

Отказ от ответственности: Я просто счастливого пользователя и не имею никакого отношения к РБУ


Пояснения

[a-zA-Z0-9]+?\.(19|20)[0-9]{2}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01]) 

Options: case insensitive 

Match a single character present in the list below «[a-zA-Z0-9]+?» 
    Between one and unlimited times, as few times as possible, expanding as needed (lazy) «+?» 
    A character in the range between “a” and “z” «a-z» 
    A character in the range between “A” and “Z” «A-Z» 
    A character in the range between “0” and “9” «0-9» 
Match the character “.” literally «\.» 
Match the regular expression below and capture its match into backreference number 1 «(19|20)» 
    Match either the regular expression below (attempting the next alternative only if this one fails) «19» 
     Match the characters “19” literally «19» 
    Or match regular expression number 2 below (the entire group fails if this one fails to match) «20» 
     Match the characters “20” literally «20» 
Match a single character in the range between “0” and “9” «[0-9]{2}» 
    Exactly 2 times «{2}» 
Match the regular expression below and capture its match into backreference number 2 «(0[1-9]|1[012])» 
    Match either the regular expression below (attempting the next alternative only if this one fails) «0[1-9]» 
     Match the character “0” literally «0» 
     Match a single character in the range between “1” and “9” «[1-9]» 
    Or match regular expression number 2 below (the entire group fails if this one fails to match) «1[012]» 
     Match the character “1” literally «1» 
     Match a single character present in the list “012” «[012]» 
Match the regular expression below and capture its match into backreference number 3 «(0[1-9]|[12][0-9]|3[01])» 
    Match either the regular expression below (attempting the next alternative only if this one fails) «0[1-9]» 
     Match the character “0” literally «0» 
     Match a single character in the range between “1” and “9” «[1-9]» 
    Or match regular expression number 2 below (attempting the next alternative only if this one fails) «[12][0-9]» 
     Match a single character present in the list “12” «[12]» 
     Match a single character in the range between “0” and “9” «[0-9]» 
    Or match regular expression number 3 below (the entire group fails if this one fails to match) «3[01]» 
     Match the character “3” literally «3» 
     Match a single character present in the list “01” «[01]» 


Created with RegexBuddy 
Смежные вопросы