#1 2019-03-13 03:33

vertigo
Member
Registered: 2019-03-10
Posts: 7

Suggestions & Questions (text file to hold find/replace pairs & regex)

I have a few suggestions for and a couple questions about this program. The suggestions are obviously meant for the developers, though anyone is welcome to give thoughts on them.

Topic №1

The first suggestion is to add options to the Case rule to allow for capitalizing all words except those not capitalized in titles (articles, prepositions, etc, e.g. a/an/and/of/the/from/with/in/out/at/on/this/up/by/for/to/is) UNLESS those words are the first in a group of words. So for example, "an example sentence - this is an example of the type of sentence" would normally be changed (with capitalize every word or capitalize and preserve options) to "An Example Sentence - This Is An Example Of The Type Of Sentence" and by putting those words in the "force case for fragments" box it would result in "an Example Sentence - this is an Example of the Type of Sentence." However, what I'd really like is "An Example Sentence - This is an Example of the Type of Sentence" ("An" at the beginning and "This" at the beginning of the second part capitalized, despite being in the forced list). It seems to me the best way to do this would be to add options for when to ignore/bypass changing forced words. One such option would be when it's the first word (another possible option would be to always capitalize the first letter, which would be selectable in addition to the main selection). Another would be when it follows a non-alphanumeric character plus a space (i.e. in any case where there's a character that's not a number or letter, followed by a space, followed by one of the forced words). So in my example sentence, "this" wouldn't be forced because it follows "- " ("- this"), so it would be capitalized. And a third option would be to allow the user to enter any characters or strings that, if they precede one of the forced words, the word won't be forced. So, for example, the user could enter "- *|*~ " (without the quotes) in the box, so any of those words that follow a - or ~ followed by a space wouldn't be forced. As it is, I was able to work around it with a very long, convoluted replace rule, but it would be so much better if that wasn't necessary.

Topic №2

The second suggestion is to allow whole word alternatives in replace vs letter-by-letter. For example, if I want to match "picture" or "image" I can do [pi][im][ca][tg][ue] which will match pictu and image as well as pmctu, pmatu, iiage, and so many other possible iterations. Not only is that more complicated to derive, but it runs the risk of potentially having an unintended match of one of the iterations, and it also creates a problem for words of different lengths, such as picture (7 letters) and image (5 letters), e.g. if I want to replace either word plus the content after them with "photo" plus the additional content, so "picture 123" and "image 456" become "photo 123" and "photo 456" the letter-by-letter system won't work, because [pi][im][ca][tg][ue]* > photo$6 would result in "photore 123" and "image 456." Maybe curly brackets could be used for this, so "{picture|image}*" would give the desired result. By the way, I realize for this example I could just do picture* > photo$1 and image* > photo $1 separately, but this is a very simplified example. This ability would definitely be useful for more complicated scenarios.

Topic №3

The third suggestion is to add the various special abilities (wildcards, etc) to translit, i.e. find* > replace (e.g. picture*> photo would replace picture123 and pictures123 with photo, though even better would be to have back references and []'s as well, so something like picture*[0-9]* > photo $2$3 could be done). Essentially, it would be the same as replace but in an easier to use line-by-line layout, which is really all it is anyway. Short of that, would it be possible to use a Pascal script to do that using items from a file? Example lines would be:

scanned image* > scan$1
image* > photo$1
[example|test] file > new name (would rename both "example file" and "test file")

Topic №4

And finally, I'm trying to find a way to match and replace a part of a filename only if other specified parts don't exist. For example, given the following files:

100 foo 123 bar 829
100 foo 123 bar
100 foo 123
foo 123 bar 829
123 bar 829
foo 123 bar

I would want to leave all of them alone except the last one, because all the others have more than one set of digits. So for the last one only, I'd want to modify the digits, specifically 1x23 (or 12x34 if it were "foo 1234 bar"). It seems regex might be able to do this, but I tried this:

(^[0-9][0-9])*[0-9][0-9][0-9] *(^[0-9][0-9])
$2$3x$4$5 $6

and it didn't work, so I don't know if my regex is just wrong or if it's not possible. I figure I could use if>then statements in a Pascal script to do it, but while I have some experience writing code, I'm not familiar with Pascal. Any help on figuring it out would be much appreciated.

Last edited by den4b (2019-03-17 11:24)

Offline

#2 2019-03-17 11:28

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: Suggestions & Questions (text file to hold find/replace pairs & regex)

Topic №1

A similar enough suggestion is currently pending implementation.

See the original topic for the reference:
Capitalize the character that follows the specified characters

In the meantime, you can use the Regular Expressions rule to capitalize the first letter in a word that is not preceded by another word. So the full solution could like the following renaming rules:

1) Case: Capitalize every word (skip extension), Force case fragments "a" "an" "and" "of" "the" "from" "with" "in" "out" "at" "on" "this" "up" "by" "for" "to" "is"
2) Regular Expressions: Replace expression "(\A|[^\w\s]\s+)(\w)" with "$1\U$2" (skip extension)

Input:

AN EXAMPLE SENTENCE - THIS IS AN EXAMPLE OF THE TYPE OF SENTENCE

Output:

An Example Sentence - This is an Example of the Type of Sentence

Topic №2

The Replace rule is not intended to handle complex patterns, that is what the Regular Expressions rule is designed for.

See the wiki on how to use alternatives:
https://www.den4b.com/wiki/ReNamer:Regu … ternatives

Topic №3

I believe the answer is same as in Topic №2. You should use the Regular Expressions rule for complex pattern matching.

Topic №4

Again, the Regular Expressions rule to the rescue.

Replace expression "\A([^\d]+)(\d+)(\d{2})([^\d]+)\Z" with "$1$2x$3$4" (skip extension).

Input:

100 foo 123 bar 829
100 foo 123 bar
100 foo 123
foo 123 bar 829
123 bar 829
foo 123 bar
foo 1234 bar

Output:

100 foo 123 bar 829
100 foo 123 bar
100 foo 123
foo 123 bar 829
123 bar 829
foo 1x23 bar
foo 12x34 bar

P.S. Please split multiple questions/suggestions into individual posts in the future.

Offline

#3 2019-03-17 18:12

vertigo
Member
Registered: 2019-03-10
Posts: 7

Re: Suggestions & Questions (text file to hold find/replace pairs & regex)

Topic 1 Thanks, I posted a reply there to move the discussion related to this into that thread.

Topics 2 & 3 I understand replace isn't meant for more complex stuff, but to do the same with regex would be far more complicated, and similar to what was stated in the thread from topic 1, adding a bit more ability to other features, like replace, would help users accomplish more without having to use regex. I like regex to an extent, as it can be quite powerful, but in my experience it can also be inconsistent and a pain to do, and I've spent a lot more time than I'd like working with it to get it to work as desired both in this app and elsewhere, so a simpler option would be very welcome.

Topic 4 Thanks!

My apologies for the big post. I've been told the complete opposite elsewhere before, being told not to do multiple posts at once, but I'll try to keep it in mind in the future. Thanks for all the help. smile

Offline

Board footer

Powered by FluxBB