Regex to ignore invalid file names

Asked

Viewed 211 times

2

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

My regular expression:

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

I’m getting this mistake:

appcfg.py: error: Error Parsing /home/klarkc/project/dist/app.yaml: while Scanning for the next token found Character '|' that cannot start any token in "/home/klarkc/project/dist/app.yaml", line 49, column 18.

  • You need an expression that ignores the characters: .\~#%&*{}:<>?|"-!, right?

  • That’s right, let it work in yaml

3 answers

2

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

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

in its original failed to escape the

  • . -> Equals for any character
  • {} -> to inform a number of repeaters ex .{4}
  • :-> I don’t know the functionality, "someone edits"
  • ? -> means that the expression has to end like this
  • | -> Operator OR
  • - -> used for groups, type 0-9

2


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

Expression:

^[\w\-. ]+$

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

Expression:

^[^\w\-. ]+$

Source: Regular Expression for Valid filename.

  • Could you deny this expression? Since the parameter is to filter the files that will be ignored and not the files to be approved.

  • Although the other @Gomiero solution worked, in the end I ended up using your solution, because it filters everything that is not valid, instead of searching for specific characters. The only change I made was to use the regex like this: ^.[^\w-. s/]+.$ to also add the directory tab to the accepted character list and . * to match previous and later characters respectively.

  • 2

    @Walkerleite you made an issue that changed substantial things in the answer, so it was rejected. When suggesting substantial changes that may change the meaning of the question/answer, notify the author of the changes and ask him to do so himself.

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.