#1 2022-12-10 20:16

Lauraq
Member
Registered: 2016-10-02
Posts: 86

capitalize the first letter if there is a word

HI smile

I have a big list of files named :


4377631753733131 (pro alber con tr33)
886uhghsdfdsfh (pro cios tui tr32)
rtyqrey 6y46457 6372576 (Flrt ghnap tsr)
537657QQRFytyvg  (flipzz Reyhdf frfg33)

I would like all words after "pro" to be capitalized. If "pro" is not present, all words in the brackets must be lowercase, for have :

4377631753733131 (pro Alber Con Tr33)
886uhghsdfdsfh (pro Cios Tui Tr32)
rtyqrey 6y46457 6372576 (flrt ghnap tsr)
537657QQRFytyvg  (flipzz reyhdf frfg33)

the initial part of the file name must not be changed

I imagine it's very difficult... be patient sad

Offline

#2 2022-12-10 21:10

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: capitalize the first letter if there is a word

Ok - next door opens and another quest apears wink - just like here!

I could have solved this (with a regular expression rule) if you just wanted it all upper case after the pro.

Take a look here. or use this replacement settings:

(?<topro>\([^)]*?\bpro +)(?<afterpro>.*?\))|(?<withoutpro>\(.*?\))
${topro}\U${afterpro}\L${withoutpro}\E

If you change the \U in the replacement to a \u only the first character will be put upper case ... but that is also not every first character of every word.

This might have been possible if the RegExp-library for pascal would have been more complete ... but that is theoretically by now.

So for a complete solution I just see the need for a Pascal Script rule. Maybe I'll work on one later ...

edit: hardened the regexp

Last edited by jogiwer (2022-12-10 22:27)

Offline

#3 2022-12-10 23:41

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: capitalize the first letter if there is a word

Ok - got somewhat deeper into it.

If you know a maximum off words which could follow "pro" than a pattern could be build for that (the more words the longer the pattern).

So I try to capture each word in two parts: "first letter" and "rest". This is done with:

(?:(?<uN> +[^)])(?<lN>[^ )]*))?

And the replacement will be:

\U${uN}\L${lN}

Replace the "N"s with numbers from 1 to ... Putting all together with (for example) 4 words you'll get:

\((?:(?<topro>[^)]*?\bpro\b)(?:(?<u1> +[^)])(?<l1>[^ )]*))?(?:(?<u2> +[^)])(?<l2>[^ )]*))?(?:(?<u3> +[^)])(?<l3>[^ )]*))?(?:(?<u4> +[^)])(?<l4>[^ )]*))? *|(?<withoutpro>.*?))\)
(${topro}\U${u1}\L${l1}\U${u2}\L${l2}\U${u3}\L${l3}\U${u4}\L${l4}\L${withoutpro})\E

You can see how long this could get big_smile

If less is needed delete some blocks and if more is needed add some. But keep in mind that this solution is not as flexible as regular expressions could be. Here only Pascal Script would help.

See https://regex101.com/r/BrVQ6z/4 for further details.

Offline

#4 2022-12-10 23:47

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: capitalize the first letter if there is a word

BTW

  1. you didn't say that "pro" would only be the first word - if that is the case there could be made some tuning.

  2. if there were multiple "pro" words the expression hooks to the first

  3. a pair of brackets could not contain further closing brackets - as this in enforced you could also specify multiple bracket piars with or without "pro" in one filename. All are handled seperatly

Offline

#5 2022-12-11 09:13

Lauraq
Member
Registered: 2016-10-02
Posts: 86

Re: capitalize the first letter if there is a word

thank you so much!!!

the word "pro" appears only once, there is "(pro" and then a maximum of 6 words

in some cases the name can contain 2 brackets such as for example

4X377631753GU733131 (flrd Ghnap Tsr) (pro Alber con Tr33)

and I would like to get

4X377631753GU733131 (flrd ghnap tsr) (pro Alber Con Tr33)


I have put your code in the Regular expression but I receive a msg of error:
"Preview process has bee terminated due to a critical error: TRegExpr(comp): Urecognized Modifier (pos 13)

Thanks smile

Last edited by Lauraq (2022-12-11 09:31)

Offline

#6 2022-12-11 12:02

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: capitalize the first letter if there is a word

Oh sorry - that has been my fault.

From the documentation of the RegExp library (TRegExpr) ReNamer has in use I read the named captures could be used ... but after short trouble I kept on checking at regexp101.

Fortunately I read that Denis is using an updated library in his beta so upcoming versions would be more flexible big_smile

Back to your szenario:
  • I threw away all what ReNamer can not cope with - sadly there only remain numbers in the replace part

  • seeking "pro" is only direct after "("

  • up to 6 words

  • still multiple bracket pairs possible

\(((pro\b)(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))? *|(.*?))\)
(${2}\U${4}\L${5}\U${7}\L${8}\U${10}\L${11}\U${13}\L${14}\U${16}\L${17}\U${19}\L${20}\L${21})

And again a link to the colorful regexp101.

Last edited by jogiwer (2022-12-11 12:04)

Offline

#7 2022-12-11 12:13

Lauraq
Member
Registered: 2016-10-02
Posts: 86

Re: capitalize the first letter if there is a word

now is perfect ! smile
You are a genius ^_^

Thanks for all your help!

Last edited by Lauraq (2022-12-11 14:01)

Offline

#8 2022-12-11 22:36

Lauraq
Member
Registered: 2016-10-02
Posts: 86

Re: capitalize the first letter if there is a word

sorry @jogiwer
I realized that there are more than 6 words, sometimes even 9. I tried to modify the commands (so as not to bother you again) as you told me but it doesn't work well for me, can you tell me what's wrong?

\(((pro\b)(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))?(( +[^)])([^ )]*))? *|(.*?))\)
(${2}\U${4}\L${5}\U${7}\L${8}\U${10}\L${11}\U${13}\L${14}\U${16}\L${17}\U${19}\L${20}\U${22}\L${23}\U${25}\L${26}\U${28}\L${29}\U${31}\L${32})\L${34}) 

thanks smile

Last edited by Lauraq (2022-12-11 22:38)

Offline

#9 2022-12-12 00:01

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: capitalize the first letter if there is a word

Hi - you could have added what went wrong.

The pattern looks ok for me. But in the replacement you have two characters to much:

...\L${20}\U${22}\L${23}\U${25}\L${26}\U${28}\L${29}\U${31}\L${32})\L${34})

The numbering looks good. The blank at the end might have found a way just into your post. But there is an additional bracket after backreferens number 32!

Offline

#10 2022-12-12 00:08

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: capitalize the first letter if there is a word

Oh yikes

Just checked for fault in style but not in number.

In the upper line you added one more "word" than in the replacement. So you have to reduce one or stretch the other (up to number 36).

(${2}\U${4}\L${5}\U${7}\L${8}\U${10}\L${11}\U${13}\L${14}\U${16}\L${17}\U${19}\L${20}\U${22}\L${23}\U${25}\L${26}\U${28}\L${29}\U${31}\L${32}\U${34}\L${35}\L${36})

Offline

Board footer

Powered by FluxBB