Regex Matching

Started by Darius1968, February 10, 2018, 10:40:28 AM

Previous topic - Next topic

Darius1968

Consider this regular expression: 
([A-Z]{1}[a-z]{1,}){1,}\.

The above has been used as Regex for the file name, in both, the search bar (with the option to search only file names enabled) and in global filtering (metadata search on just the "File Name" tag. 

Consider that IMatch is coming up with things like:
IMG_4269_resize.JPG
IMG_4257_resize.JPG
These are not valid, when I test at this regular expressions website:  https://regex101.com/

What am I doing wrong? 

Mario

IMatch uses the Boost regexp engine, which implements the PERL regexp syntax.
The site you quote does not seem to support PERL regexp.

Besides, I'm no regexp expert. I cannot help you with such complex expressions, sorry.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Aubrey

Quote from: Darius1968 on February 10, 2018, 10:40:28 AM
Consider this regular expression: 
([A-Z]{1}[a-z]{1,}){1,}\.

([A-Z]{1}
I think this only matches the first character i.e., matches A or B or... or Z repeated once.  It will only match upper case alphabet
[a-z]{1,} matches [a-z] repeated once or more times only matching lowercase alphabet
then (...){1,} looks like it will accept whatever is in the brackets repeated once or more times

hmmm... I wonder if the issue is with the digits, if there are digits in the filename this is probably not being recognized

What are you trying to match? Perhaps we can come up with a better expression.

I expect you have looked at the "Regular Expressions" topic in the help file and the associated recommend URLs at the bottom of the page?

Aubrey.

Darius1968

Yes, I have.  I'm simply trying to match things like:
MyBestFriend.jpg
GetMystified.jpg
FantasyIsland.gif
etc. 

Jingo

recommend giving regexbuddy a shot.... it is surprisingly good at building complex regex expresssions for you in a multitude of target "languages"....  believe there is a freeware version or full demo available.

Aubrey

#5
Quote from: Darius1968 on February 10, 2018, 12:14:11 PM
Yes, I have.  I'm simply trying to match things like:
MyBestFriend.jpg
GetMystified.jpg
FantasyIsland.gif
etc.

As far as I can see the only thing in common with these files is "d."
The CamelCase is also common between the files - is this what you are trying to match? It's really not clear what you would like to match.
Aubrey.

Darius1968

Audrey, I'm not even trying to match anything.  All I want to achieve is have my regular expression search match file names that at any spot within the name itself, there is a capital letter, followed by a series of lowercase letters, that own up to a single word.  One or more such words can exist in the file name.  The arbitrary file names I've provided, are just meant to serve as examples of the types of file names I'm after. 

Mario

The IMatch search engine matches regular expressions case-insensitive.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Darius1968

Well, this post was motivated by this post (https://www.photools.com/community/index.php?topic=7717.0), in which someone wanted a way to use Regex in the file renamer, to insert a space between word boundaries (points of char. 1=lowercase & char. 2=uppercase).  This post led to your implementing case-sensitive Regex processing.  Now, my question is if the possibility of case-sensitive Regex processing can be added to the search engine, as well as the renamer.  After all, it would be nice to be able to use the search engine to weed out those files that qualify as examples, for which this insertion of space applies. 

Mario

#9
Having case-sensitive regexp in the Renamer, including the corresponding dialog option and other things makes sense for some specific renaming-related tasks.

I don't see that changing the IMatch search engine to use case-sensitive regular expressions (or even adding modes and switches everywhere it's used to allow a user / app / IMatch / IMWS to choose). That would be a lot of work.

The search engine is in place since 2014 and no user ever added a feature request for case-insensitive matching.
I doubt that more than a handful of users ever uses regular expressions, at all.
Over past versions I've actually simplified the search engine and the file window search bar, instead of adding more and more options only a few users will ever need.

I know that for you, with your specific task at hand, having case-sensitive regexp would be beneficial.
But for how many other users would that be useful?
It took maybe one hour to enhance the Renamer. To do the same for the search engine will take several days, because of all the UI work, IMWS changes, documentation updates etc. that are linked to that.

I suggest you make a feature request and then we'll see.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Aubrey

A search on the web showed this site: (I used "identify camel case with Regex")

https://stackoverflow.com/questions/19021873/upper-and-lower-camel-case

On reading through and experimenting with the website of the Online regex tester: https://regex101.com/
This might well be the solution that you are looking for:
[A-Z][a-z]*([A-Z0-9]+[a-z]*)+

Let us know if this solves your particular case.

Aubrey.

Darius1968

Aubrey, I tried your solution, which didn't work.  I'm not at all surprised, however, because Mario has specified in this thread that IMatch's handling of regular expressions in its search engine is such that it doesn't even make a distinction between upper and lowercase characters. 

Erik

Couple of thoughts related to your problem.

If you are just using this to confirm what files will qualify for a rename, perhaps one of the following will work for your situation.

1. Why not use the renamer?  I thought it had an option of "testing", i.e. seeing what the renaming will look like prior to actually implementing the rename action.
2. Create a category based on Regex (assuming those would be case sensitive).
3. Use a file explorer that can handle regex for a search routine and use a file search there to see what the results look like.  (I use Xyplorer as my file browser and I believe it can do this).
4. Export a list of your file names into a text file and then use a text editor that can find using regex to find files in your list

I know none of these are ideal, and they could even be more work, but then again many of us using Regex have put in a lot of work to understand and use it anyway.  Strangely, the only reason I know how to use Regex is a result of DAM software (originally for my music collection but reinforced by IMatch) mostly for renaming files, version control, and categorizing files (audio and photos).