我需要一个正则表达式来检查一个字符串(文件名) [英] I need a regular expression to check a string (filename)

查看:119
本文介绍了我需要一个正则表达式来检查一个字符串(文件名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个正则表达式来检查一个字符串(FileName)



1.它只能包含数字。

2.它只能包含Alphabetes。

3.它只能包含下划线。

4.它可以包含数字,字母,下划线,空格,短划线( - )的组合。

5.它必须只包含一个或零。(点)。

6.之后。(点)只允许使用Alphabetes和Numbers。

7.字符串的长度不应超过200个字符。

8.不得包含特殊字符或任何其他内容。

9 。不得仅包含空格。

10.不得仅包含短划线。

11.不得包含多个点。



我试过这个



1. [^ a-zA-Z 0-9 _.-]



2. [^ a-zA-Z 0-9 _-] +(。[jJ] [pP] [gG] |。[gG] [iI] [fF])$



但是没有工作。



它可以除了这些字符串 - 1.pdf,a.pdf,abc。 jpg,_.pdf,a1.jpg,1a_.pdf,1 a-.pdf,abcd。



不应接受这些字符串 - abc.phb.pdf ,abc.phb.jpg,a%im.jpg,.. jpg,..pdf,.pdf,.jpg,-.pdf。

I need a regular Expression to check a string (FileName)

1. it can contain only numbers.
2. it can contain only Alphabetes.
3. it can contain only Underscore.
4. it can contain Combination of numbers,alphabets,Underscore,space,dash(-).
5. it must contain only one or zero .(dot).
6. After .(dot) only Alphabetes and Numbers are allowed.
7. Lenght of string should not be more than 200 character.
8. Must not contain special character or any other thing.
9. Must not contain space Only.
10. Must not contain dash only.
11. Must not contain more than one dot .

I have tried this

1. [^a-zA-Z 0-9_.-]

2. [^a-zA-Z 0-9_-]+(.[jJ][pP][gG]|.[gG][iI][fF])$

but not working.

it can except these strings -- 1.pdf ,a.pdf , abc.jpg, _.pdf , a1.jpg , 1a_.pdf , 1 a-.pdf , abcd .

Should not accept these strings -- abc.phb.pdf , abc.phb.jpg , a%im.jpg ,..jpg , ..pdf , .pdf, .jpg , -.pdf .

推荐答案





但没有工作。



它可以除了这些字符串 - 1.pdf,a.pdf,abc .jpg,_.pdf,a1.jpg,1a_.pdf,1 a-.pdf,abcd。



不接受这些字符串 - abc.phb.pdf,abc.phb.jpg,a%im.jpg,.. jpg,.. pdf,.pdf,.jpg,-.pdf。


but not working.

it can except these strings -- 1.pdf ,a.pdf , abc.jpg, _.pdf , a1.jpg , 1a_.pdf , 1 a-.pdf , abcd .

Should not accept these strings -- abc.phb.pdf , abc.phb.jpg , a%im.jpg ,..jpg , ..pdf , .pdf, .jpg , -.pdf .


尝试:

Try:
^([A-Za-z0-9\-_][A-Za-z0-9\-_\s]*)(\.[A-Za-z0-9\-_]*)




并检查在Regex之外手动完成总长度。


And check the total length manually outside the Regex.


这篇关于我需要一个正则表达式来检查一个字符串(文件名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆