Regex to ignore invalid filenames

2

Hello, I'm trying to add a regex in app.yaml to ignore files with strange names in Google App Engine , but it is not working.

My regular expression:

skip_files:
- [.\~#%&*{}:<>?|\"-!]

I'm getting this error:

  

appcfg.py: error: Error parsing /home/klarkc/project/dist/app.yaml:   while scanning for the next token found character '|' that can not   start any token in "/home/klarkc/project/dist/app.yaml", line 49,   column 18.

    
asked by anonymous 20.01.2016 / 20:56

3 answers

2

The expression below allows you to match only the alphabetic characters letters A..Z and a..z and numbers 0..9 and symbols - , _ , . , and whitespace see.

Expression:

^[\w\-. ]+$

To do the inverse and allow only the special symbols *&%#^~ , just use the denied ^ list, see below:

Expression:

^[^\w\-. ]+$

Source: Regular expression for valid filename.

    
02.02.2016 / 16:43
2

You need to escape some characters, see below how your regex should be;

[\.\~#%&\*\{\}\:<>\?\|\-!]

in its original missed escape

  • . - > Equivalent to any character
  • {} - > to report a number of repeaters ex .{4}
  • : - > I do not know the functionality, "someone edits"
  • ? - > means that you have to end the expression
  • | - > Operator OU
  • - - > used for groups, type 0-9
04.02.2016 / 16:55
1

The expression below, finds the names files with the characters of the list .\~#%&*{}:<>?|"-!: :

^[^\\#\%\&\*\{\}\:\<\>\?\|\"\-\!]+$


See a use case running on regex101

^ match at the beginning of the line

+ one or more times

$ match at end of line

More examples (perhaps better) in: Skipping Files .

To validate the syntax of the files YAML (before using them):

Online YAML Parser

Code Beautify - YAML Validator

YAML Lint

    
04.02.2016 / 21:41