【问题标题】:The file name must only contain ASCII 32-126 characters except some special character文件名只能包含 ASCII 32-126 字符,一些特殊字符除外
【发布时间】:2019-09-29 12:08:00
【问题描述】:

我有一个文件,我需要对其进行一些正则表达式验证。

验证是文件名只能包含 ASCII 32-126 个字符,
除了:–34 ["] –39 [’] –59 [;] –60 [<] –61 [=] –62 [>] –92 [\]

此外,文件名不能包含以下字符序列:–%00

let filename = "filename"
let regex = ""
console.log(filename);

有人可以看看并告诉我解决方案吗? 谢谢

【问题讨论】:

  • 你自己有没有尝试过?

标签: javascript regex ascii


【解决方案1】:

您可以使用以下正则表达式:

^(?:(?!["';<=>\\])[\x20-\x7E])+$

Regex Demo

解释:

^                  # start of line
(?:                # non-capturing group
   (?!["';<=>\\])  # negative lookahead - do not to match if contains given symbols
   [\x20-\x7E]     # match in range from ASCII 32-126
)                  # close non-capturing group
+                  # match 1-unlimited times
$                  # end of line

【讨论】:

    猜你喜欢
    • 2013-12-04
    • 1970-01-01
    • 2013-06-30
    • 1970-01-01
    • 2018-05-09
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多