Regex code how to filter all names that contain only numbers and end with .jpg and/or _number.jpg?

StackOverflow https://stackoverflow.com/questions/23198592

سؤال

How to filter all names that consist of numbers and end with .jpg and/or _number.jpg?

Background info: In SSIS 2008 I have a foreach loop that will store the filename into a variable for all jpg files. The enumorator configuration for Files is currently: *.jpg This will handle all jpg files.

What is the code so it will only handle names likes?:

3417761506233.jpg
3417761506233_1.jpg
5414233177487.jpg
5414233177487_1.jpg
5414233177487_14.jpg

but not names like:

abc.jpg
abc123.jpg
def.png
456.png

The numbers represent EAN codes by the way. I thought about this code:

\d|_|.jpg

but SSIS returns an error stating there are no files that meet the criteria eventhough the files(names) are in the folder.

enter image description here

هل كانت مفيدة؟

المحلول

You could use a Script Task within the loop to do the regex filtering: http://microsoft-ssis.blogspot.com/2012/04/regex-filter-for-foreach-loop.html enter image description here

Or you could use a (free) Third Party Enumerator: http://microsoft-ssis.blogspot.com/2012/04/custom-ssis-component-foreach-file.html enter image description here

نصائح أخرى

For that, you can use the following regex:

^\d+(_\d+)?.jpg$

Demo: http://regex101.com/r/qC7oV3

^(\d+(?:_\d+)?\.jpg$)

DEMO --> http://regex101.com/r/dM9rJ7

Matches:

3417761506233.jpg
3417761506233_1.jpg
5414233177487.jpg
5414233177487_1.jpg
5414233177487_14.jpg

Excludes:

abc.jpg
abc123.jpg
def.png
456.png
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top