I am looping through an Array of Image Filenames which are as below:
- ConImage1 - Core.png
- ConImage211 - Core.png
- ConImage34 - Core.png
- ConImage09 - Core.png
- ConImage11 - Core.png
- ConImageOri23.png
- ConImageOri2.png
- ConImageOri11.png
- ConImageOri132.png
- ConImageForEng7 - Core.png
- ConImageForEng12 - Core.png
- ConImageForEng11 - Core.png
- ConImageForEng10 - Core.png
- ConImage1-Dislikes-Core.png
- ConImage1-Likes-Core.png
- ConImage12 - Dislikes - Core.png
- ConImage12 - Likes - Core.png
- ConImage34 - Dislikes - Core.png
- ConImage34 - Likes - Core.png
- ConImage55 - Dislikes - Core.png
- ConImage55 - Likes - Core.png
I need a Regex pattern that will only match the following Filenames:
- ConImage1 - Core.png
- ConImage211 - Core.png
- ConImage34 - Core.png
- ConImage09 - Core.png
ConImage11 - Core.png
ConImageOri23.png
- ConImageOri2.png
- ConImageOri11.png
- ConImageOri132.png
and exclude the filenames containing the words : Likes, Dislikes, ForEng etc.
Edit:
I am not good at regex but trying something like this to limit my search.
^(ConImage|(Orig|!ForEng)){1}[0-9\ \-]+[\W(Dislikes|Likes)][0-9\ \-]+(Core\.png)$/i/g
OR the below works for finding necessary files, but if some odd name comes out e.g. ConImageMaxx12 - Core.png etc, it also picks that up.
^ConImage((?!ForEng|Dislikes|Likes).)*$
I don't want to implement VBA.Filter function but need a Regex solution.
Any help would be most appreciated.
Without specific rules, it is hard to come up with a regex. To match the specific values you have posted (and exclude the
ConImageMaxx12you mentioned in a comment), you could try:Edit to correct the missing "Start of String" token
That regex matches:
ConImageOriForEng,Likes,Dislikesand other derivatives)Whether that set of rules is sufficient to eliminate the unwanted file names cannot be stated, since I am only guessing at some rules based on what you've written.
Here is a more formal explanation of the Regex with some links to a tutorial explanation:
Note that, in accordance with your comments, we set the case-insensitive option
Match Specific File Names
Options: Case insensitive; ^$ match at line breaks
^ConImage(?:Ori)??Ori\d++(?:(?!(?:For|Likes)).)**(?!(?:For|Likes))(?:For|Likes)ForForLikesLikes.$Created with RegexBuddy