I have a regex which looks like this:
((C1)(.*?))?((C2)(.*?))?((C3)(.*?))?((C4)(.*?))?(\.zip|$)
"C" stands for Constant here, they are always the same. What comes in-between them is different every time (and sometimes nothing/whitespace. Please see my working example here!
https://regex101.com/r/R1Btde/2
This matches anything from
C1 Anything C2 Anything C3 Anything C4 Anything.zip
or
C3 Anything C4 Anything.zip
to something without an extension like:
C1 Anything C4 Anything
The problem is at the moment I am having to end my REGEX with (\.zip|$)
to make the .zip
file extension optional (as some files will be directories). Unfortunatelty this matches 'Nothing' every time.
Is there a way of stopping Group 13 matching with the end of every line, whilst still maintaining this group structure? You can see the groups on my working example. This isn't a duplication of my previous question, it's just a continuation as I try to improve this REGEX to support directories and files without extensions. I really appreciate the help you guys have given me and I wouldn't have got this far without you!
Many thanks!