I'm trying to create regex which will list all .jpg
in some directory except few files(static, not a pattern).
So, I've wrote this:(Python)
"^(?!358097_sat!823133_sat!140860_sat).*jpg$"
"^(?!358097_sat|823133_sat|140860_sat).*jpg$"
I want to list all JPEG files except for:
- 358097_sat
- 823133_sat
- 140860_sat
But it gives me an error saying that no file found matching this pattern.
Here is the complete string and error message:
No files matched pattern: ../input/dataset/valid/^(?!358097_sat!823133_sat!140860_sat).*jpg$
I'm actually passing this regex to a tf-function:
tf.data.Dataset.list_files(dataset_path val_data "^(?!358097_sat|823133_sat|140860_sat).*jpg$", seed=SEED)
# dataset_path = "../input/dataset/"
# val_data = "valid/"
Complete error:
*InvalidArgumentError: Expected 'tf.Tensor(False, shape=(), dtype=bool)' to be true. Summarized data: b'No files matched pattern: ../input/dataset/valid/^(?!358097_sat|823133_sat|140860_sat).jpg$'
Here is the function reference: https://www.tensorflow.org/api_docs/python/tf/data/Dataset#list_files
CodePudding user response:
You need to put brackets round the 3 options.
"^((?!(358097_sat!823133_sat!140860_sat)).) jpg$"
CodePudding user response:
You need to put brackets round the 3 options and use pipes |
between the options and not !
as in your first version.
^((?!(358097_sat|823133_sat|140860_sat)).) \.jpg$