I am looping through an Array of Image Filenames which are as below:
I need a Regex pattern that will only match the following Filenames:
ConImage11 - Core.png
ConImageOri23.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 ConImageMaxx12
you mentioned in a comment), you could try:
Edit to correct the missing "Start of String" token
^ConImage(?:Ori)?\d+(?:(?!(?:For|Likes)).)*$
That regex matches:
ConImage
Ori
ForEng
, Likes
, Dislikes
and 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
^ConImage(?:Ori)?\d+(?:(?!(?:For|Likes)).)*$
Options: Case insensitive; ^$ match at line breaks
^
ConImage
(?:Ori)?
\d+
(?:(?!(?:For|Likes)).)*
$
Created with RegexBuddy