Moving word in unknown position to beginning

Bulk Rename Utility How-To's

Moving word in unknown position to beginning

Postby TaketaD » Wed Aug 02, 2023 3:08 am

At the moment, I'm using:

Code: Select all
%1 Word %2
Word - %1 %2

(Thank you Admin)

This works in 90% of cases. The problem I'm running into is when the word is the first or last, the match doesn't catch it. I assume it's because there's no %1 or %2 group. Can the match expression be modified to account for this possibility?

Thank you
TaketaD
 
Posts: 5
Joined: Wed Aug 02, 2023 2:32 am

Regex: Move word to beginning

Postby Luuk » Wed Aug 02, 2023 7:36 am

If removing the checkmark from "Simple", can use a "Match" and "Replace" like...
(^|.+ )Word( .+|$)
Word - \1\2

If unsure for the extra spacing, then Remove(5) does also have checkboxes for "D/S" and "Trim".
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: Moving word in unknown position to beginning

Postby TaketaD » Wed Aug 02, 2023 6:01 pm

That works perfectly, thank you!

I think I understand the expression, but I'm having a hard time with the spaces. I'm not sure what their function is there? Is it just to ensure that the search query isn't part of another word?
TaketaD
 
Posts: 5
Joined: Wed Aug 02, 2023 2:32 am

Regex: Move word to beginning

Postby Luuk » Wed Aug 02, 2023 9:31 pm

Yes, but also because the original "Match" says that space should always be the border?
So these new (groups) just say the borders can be either (space or beginning/end)...

(^|.+ )Word( .+|$)
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: Moving word in unknown position to beginning

Postby TaketaD » Fri Sep 15, 2023 12:10 am

This has been working perfectly, but there are a couple of adjustments I'd like to make to let me be even lazier:

    * Since Word used in Replace will be the same as Word defined in Match, is there a way for me to simply say "Use whatever's defined here", so that I can just change the Word in Match instead of needing to change it in two different spots every time?
    * How can I make the Word in the Match query not case sensitive? If the Word found is "word", I would like to still return a hit, and then be moved to the front as "Word".

Thanks again
TaketaD
 
Posts: 5
Joined: Wed Aug 02, 2023 2:32 am

Regex: Move word to beginning

Postby Luuk » Fri Sep 15, 2023 4:17 am

(?i) says case-insensitive, and \u says uppercase next-letter, but it needs a checkmark for "v2".
So with RegEx(1) having the "v2" checkmark, your "Match" and "Replace" could be like...
(?i)(^|.+ )(word)( .+|$)
\u\2 - \1\3
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm


Return to How-To