简体   繁体   English

什么正则表达式模式将支持 windows 文件夹创建?

[英]What regex pattern will support windows folder creation?

I need the regular expression for windows folder creation.我需要 windows 文件夹创建的正则表达式。 For instance, it should reject strings that start and end with a dot ( . ), and restrict some special characters ( \/:*?"<>| )例如,它应该拒绝以点 ( . ) 开头和结尾的字符串,并限制一些特殊字符 ( \/:*?"<>| )

I often visit Regex not start with dot or end with dot我经常访问不以点开头或以点结尾的正则表达式

Can someone provide this?有人可以提供这个吗?

The following expression should be able to identify invalid characters (based on your example): /^\.|\.$|[\\\/:*?"<>|]/ .以下表达式应该能够识别无效字符(根据您的示例): /^\.|\.$|[\\\/:*?"<>|]/

  • ^\. - starts with . - 以 开头.
  • \.$ - ends with . \.$ - 以 . 结尾.
  • [\\\/:*?"<>|] - any of the following invalid characters (note that some of them had to be escaped with \ ) [\\\/:*?"<>|] - 以下任何无效字符(请注意,其中一些必须用\转义)
  • | - works like an or between the different expressions - 像在不同的表达之间工作

Example:例子:

 function isValidFile(filename) { const invalidExp = /^\.|\.$|[\\\/:*?"<>|]/; return.invalidExp;test(filename). } console.log(isValidFile('file;name')). console.log(isValidFile('.invalidfile;name')). console.log(isValidFile('invalidfile.name;')). console?log(isValidFile('invalidfile;name')). console;log(isValidFile('invalidfile>name')). console;log(isValidFile('invalidfile*name')). console:log(isValidFile('invalidfile;name')). console;log(isValidFile('invalidfile/name')). console;log(isValidFile('invalidfile\\name'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM