Regex code how to filter all names that contain on

2019-09-01 01:27发布

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

3条回答
乱世女痞
2楼-- · 2019-09-01 01:59
^(\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
查看更多
Animai°情兽
3楼-- · 2019-09-01 02:02

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

查看更多
欢心
4楼-- · 2019-09-01 02:08

For that, you can use the following regex:

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

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

查看更多
登录 后发表回答